Removing a1 field from chess board in Clingo knight path program - cycle

I need to do some symulations about knight path and Hamilton cycle on chesseboard, but i wondering what if i exclude some fields from chesseboard
xchessboard(1..8).
ychessboard(1..8).
time(1..8*8+1).
xypos(X,Y) :- xchessboard(X), ychessboard(Y).
fromTO(X1,Y1,X2,Y2) :- xypos(X1,Y1), xypos(X2,Y2),
|X1-X2| = 1, |Y1-Y2| = 2.
fromTO(X1,Y1,X2,Y2) :- xypos(X1,Y1), xypos(X2,Y2),
|X1-X2| = 2, |Y1-Y2| = 1.
1 { position(I,X,Y) : xypos(X,Y) } 1 :- time(I).
:- time(I), time(I+1), xypos(X1,Y1), xypos(X2,Y2),
position(I,X1,Y1), position(I+1,X2,Y2), not
fromTO(X1,Y1,X2,Y2).
:- time(I1-1), time(I2), I1 < I2, xypos(X,Y),
position(I1,X,Y), position(I2,X,Y).
:- position(1,X,Y), X+Y>2.
:- position(8*8+1,X,Y), X+Y>2
above is code in clingo, and i need to remove some fileds like a1 from this chesseboard but i dont have any idea how to do that, can someone help me?
Thanks

Besides that you do not have a "a1" on your chessboard but a (1,1), just do not defer the xypos/2 facts for the positions you want to remove:
xchessboard(1..8).
ychessboard(1..8).
remove(1,4).
remove(3,2).
xypos(X,Y) :- xchessboard(X), ychessboard(Y), not remove(X,Y).

Related

How can I reformat a list of items from lua to kotlin?

I am working on a project that originally started in Lua and I want to update it to Kotlin.
I have about 5000 questions/answers that look like:
['Question'][1] = "'7x' was used to refer to the secret ingredient of what drink";
['Answers'][1] = {"coca cola"};
['Question'][2] = "'And the big wheel keep on turning neon burning up above and I'm just high on the world come on and take the low ride with me girl on the.....' What's the Dire Straits song title?";
['Answers'][2] = {"tunnel of love"};
I want to change the format of these without manually going through all 5000, so that they look like:
val que1 = Question(
1, "'7x' was used to refer to the secret ingredient of what drink",
"coca cola"
)
val que2 = Question(
2, "'And the big wheel keep on turning neon burning up above and I'm just high on the world come on and take the low ride with me girl on the.....' What's the Dire Straits song title?",
"tunnel of love"
)
Please help me figure out how to reformat these questions/answers. Thanks.
You can write a script like this to get the desired output.
Step 1: Create input.txt and paste your lua code here which you want to translate
['Question'][1] = "'7x' was used to refer to the secret ingredient of what drink";
['Answers'][1] = {"coca cola"};
['Question'][2] = "'And the big wheel keep on turning neon burning up above and I'm just high on the world come on and take the low ride with me girl on the.....' What's the Dire Straits song title?";
['Answers'][2] = {"tunnel of love"};
Step 2: Create an empty file named output.txt. This file will consist of converted code.
Step 3: Run this main function. You might need to modify file path base on your directory structure. Note: This code is written in Kotlin.
fun main() {
val input = File("src/main/kotlin", "input.txt").readLines()
val outputWriter = File("src/main/kotlin", "output.txt").printWriter()
val lines = input.windowed(2, 2)
val questions = mutableListOf<String>()
lines.forEachIndexed { index, str ->
val que = str[0].split("\"")[1]
val ans = str[1].split("\"")[1]
val question = "val que${index + 1} = Question(${index + 1}, \"$que\", \"$ans\")"
println(question)
questions.add(question)
}
outputWriter.use { out->
questions.forEach {
out.println(it)
}
}
}
After running the script you will get the desired output in output.txt. Alternatively, you can also get this from the console.

Data Cleaning - Basic questions

sal_mod = sal[['Salary']]
f=lambda x : x.replace('K','000')
sal_mod = sal_mod.apply(f,axis=1)
sal_mod.head(20)
enter image description here
I run this code in the hope that I will be able remove the k from every row of the column, But Now I am sweating over it. Please help. IDK what is going wrong.
Maybe this helps - when I use :
f=lambda x: x.lower()
in the code above :
this is the error that pops up :
Series' object has no attribute 'lower'
the data :
Salary
0 ₹752K - ₹828K
1 ₹423K - ₹462K
2 ₹622K - ₹671K
3 ₹28K - ₹30K
4 ₹23K - ₹25K
5 ₹395K - ₹2,069K
6 ₹950K - ₹3,086K
7 ₹695K - ₹741K
8 ₹583K - ₹639K
9 ₹57K - ₹62K
Based on a few comments I was able to clean the data to some extent:
sal_mod = sal[['Salary']]
f=lambda x : x.str.replace('K','000').str.replace('₹','').str.replace(',','')
sal_mod = sal_mod.apply(f,axis=1)
sal_mod = pd.Series(sal_mod['Salary'],dtype="string")
sal_mod.head(20)
The following code dosent execute :
sal_min = sal_mod.apply((lambda x: x.split('-')),axis=1)
sal_min.head(20)
Can I change the data type to string, because I hit a snag after a few successful str.replace(..) I want to use split function but the result of the split function is not scriptable/iterable. it is probably because it is a text object as of now! I want to be able to convert it to integer

PHP do while with multiple while conditions

I'm hoping somone might be able to help me here. I've had a look and found someone who has had he same issue:
Do-While Loop with Multiple Conditions
However I've checked and cannot see where i'm going wrong
Here's my code:
$x=0;
$y=0;
do {
$x = rand(0,5);
$y++;
} while ($x!=5 || $y<=5);
and so I was expecting the following: Either the code to stop when X was not == 5 OR y was more than 5. However the result i got was x=5 and y=>5
To put the theory to the test i changed my code to:
$x=0;
$y=0;
echo'<br />--x-y';
do {
$x = rand(0,5);
$y++;
echo'<br />--'.$x.'-'.$y;
if($y>5)
echo"-I should finish here";
} while ($x!==5 || $y<=5);
echo "<br />x=".$x;
echo "<br />y=".$y;
and in one instance i ended up with :
--x-y
--5-1
--3-2
--4-3
--4-4
--2-5
--4-6-I should finish here
--1-7-I should finish here
--3-8-I should finish here
--3-9-I should finish here
--3-10-I should finish here
--3-11-I should finish here
--5-12-I should finish here
x=5
y=12
Any suggestions as to where i'm going wrong?
You want to stop when (X = 5 or Y > 5). The condition inside while is for continuing, so you have to inverse the condition to: (X != 5 AND Y <= 5)
De Morgan Laws

Zero padding in front using Numeral.js and Aurelia

I'm trying to build a basic Aurelia app.
Suppose I got a data where id = 1.
I can't seem to find a way to have 2 leading zero padding to my id using Numeral.js (http://numeraljs.com/).
I have this code:
<span>#${book.number | numberFormat:'000'}</span>
I was expecting an output like:
#001
but all I got was just
1
Ideally, it should go:
#001
#002
#003
...
#023
#024
#025
...
#135
#136
#137
etc
Does anyone know if this is possible ?
Thanks Stevies on Aurelia Gitter,
The solution is in the formatter class, we can go:
import numeral from 'numeral';
export class NumberFormatValueConverter {
toView(value) {
var output = new Intl.NumberFormat('en', {minimumIntegerDigits: 3, useGrouping: false}).format(value);
return output;
}
}

Jsoup simple selector code help needed please

I'm having a hard time getting the wanted info from a very simple code.
For example, I have no problem collecting my data within this simple code:
<HTML>
<TABLE>
<TABLE WIDTH=100%><TR class=FSS-data-row-highlight>
<TD> Evgeni Malkin, Pit (C/RW)</TD>
<TD class=FSS-data-right> 6 pts in last 2 GP </TD>
</TR>
</TABLE>
</TABLE>
</HTML>
What I need is the 'Evgeni Malkin 6 pts in last 2' string which works fine within that code. But when connect to the whole page, it returns nothing. I guess it is because there are tables within tables but I can't figure out how to proceed. Here is my code:
Document doc = Jsoup.connect("http://forecaster.thehockeynews.com/hockeynews/hockey/statistics.cgi?mlb&mode=hotnot/").get();
Elements scanYearplace = doc.select("tr.FSS-data-row-highlight td");
String yearplace = scanYearplace.text();
In fact I need all to grab the infos on all the other players too but it would be a start if I could that one to work.
Any suggestions?
Thanks in advance!
--- see update below ---
Please realize this is a fragile in that any change to the site could potentially break this. You'll also want to do some error checking and whatnot. Also, I didn't see the "6 pts in last 2 GP" text like you have above, but you can grab whatever stat you want using this code. Just change the stats.get(4) to whatever you want.
Document doc = Jsoup.connect("http://forecaster.thehockeynews.com/hockeynews/hockey/statistics.cgi?mlb&mode=hotnot/").get();
for (Element e : doc.select(".FSS-data-row")) {
Element td = e.select("td.FSS-data-left > a").first();
String name = (td != null?td.text():null);
Elements stats = e.select(".FSS-data-right");
String goals = (stats.size() > 0?stats.get(4).text():null);
System.out.println(name + ":" + goals);
}
Sample output:
null:null
J. Benn:13
P. Sharp:20
P. Marleau:17
T. Oshie:14
The first null:null is because that is like the header row on the page.
-----UPDATE-----
The url you had in your post pointed to the wrong page. Here is updated code to get what I think you want..
Document doc = Jsoup.connect("http://forecaster.thehockeynews.com/hockeynews/hockey/statistics.cgi?&mode=hotnot").get();
for (Element e : doc.select("tr.FSS-data-row-highlight")) {
Element tdname = e.select("td > a").first();
String name = (tdname != null?tdname.text():null);
Element tdstat = e.select("td.FSS-data-right").first();
String stat = tdstat.text();
System.out.println(name + ":" + stat);
}
Sample output:
Mathieu Perreault:5 pts in last 2 GP 
Mikhail Grabovski:5 pts in last 2 GP 
James Neal:4 pts in last 2 GP 
Kris Versteeg:4 pts in last 2 GP 
Evgeni Malkin:12 pts in last 6 GP