Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IP/out
.idea/

12 changes: 7 additions & 5 deletions IP/go.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#echo go.sh <name_of_prog> assumed in dir ./progs
mkdir out
mkdir out/production
mkdir out/production/IP
mkdir -p out
mkdir -p out/production
mkdir -p out/production/IP
export TARGET="out/production/IP"
mkdir "$TARGET"
mkdir -p "$TARGET"
rm -r -f $TARGET/iProlog
rm -f progs/*.pl.nl

#rm -f progs/*.pl.nl

javac -O -d "$TARGET" src/iProlog/*.java
swipl -f pl2nl.pl -g "pl('$1'),halt"
java -cp "$TARGET" iProlog.Main "progs/$1.pl"
Expand Down
40 changes: 40 additions & 0 deletions IP/progs/queens.pl.nl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
place_queen I _0 _1 _2 and
_0 holds list I _3 and
_1 holds list I _4 and
_2 holds list I _5 .

place_queen I _0 _1 _2 and
_0 holds list _3 Cs and
_1 holds list _4 Us and
_2 holds list _5 Ds
if
place_queen I Cs Us Ds .

place_queens nil _0 _1 _2 .

place_queens _0 Cs Us _1 and
_0 holds list I Is and
_1 holds list _2 Ds
if
place_queens Is Cs _3 Ds and
_3 holds list _4 Us and
place_queen I Cs Us Ds .

gen_places nil nil .

gen_places _0 _1 and
_0 holds list _2 Qs and
_1 holds list _3 Ps
if
gen_places Qs Ps .

qs Qs Ps
if
gen_places Qs Ps and
place_queens Qs Ps _0 _1 .

goal Ps
if
qs _0 Ps and
_0 lists 0 1 2 3 4 5 6 7 8 9 10 11 .

63 changes: 63 additions & 0 deletions IP/progs/sud4x.pl.nl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
s4x4 _0 and
_0 lists _1 _2 _3 and
_1 lists _4 _5 _6 _7 and
_4 lists S11 S12 S13 S14 and
_5 lists S21 S22 S23 S24 and
_6 lists S31 S32 S33 S34 and
_7 lists S41 S42 S43 S44 and
_2 lists _8 _9 _10 _11 and
_8 lists S11 S21 S31 S41 and
_9 lists S12 S22 S32 S42 and
_10 lists S13 S23 S33 S43 and
_11 lists S14 S24 S34 S44 and
_3 lists _12 _13 _14 _15 and
_12 lists S11 S12 S21 S22 and
_13 lists S13 S14 S23 S24 and
_14 lists S31 S32 S41 S42 and
_15 lists S33 S34 S43 S44 .

sudoku Xss
if
s4x4 _0 and
_0 holds list Xss Xsss and
map11 permute _1 _2 and
_1 lists 1 2 3 4 and
_2 holds list Xss Xsss .

map1x _0 _1 nil .

map1x F Y _0 and
_0 holds list X Xs
if
F Y X and
map1x F Y Xs .

map11 _0 _1 nil .

map11 F X _0 and
_0 holds list Y Ys
if
map1x F X Y and
map11 F X Ys .

permute nil nil .

permute _0 Zs and
_0 holds list X Xs
if
permute Xs Ys and
ins X Ys Zs .

ins X Xs _0 and
_0 holds list X Xs .

ins X _0 _1 and
_0 holds list Y Xs and
_1 holds list Y Ys
if
ins X Xs Ys .

goal Xss
if
sudoku Xss .

27 changes: 13 additions & 14 deletions IP/src/iProlog/Clause.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@

package iProlog;

/**
* representation of a clause
*/
class Clause {
Clause(final int len, final int[] hgs, final int base, final int neck, final int[] xs) {
this.hgs = hgs; // head+goals pointing to cells in cs
this.base = base; // heap where this starts
this.len = len; // length of heap slice
this.neck = neck; // first after the end of the head
this.xs = xs; // indexables in head
}

final int len;
final int[] hgs;
final int base;
final int neck;
final int[] xs;
final int len;
final int[] hgs;
final int base;
final int neck;
final int[] xs;
Clause(int len, int[] hgs, int base, int neck, int[] xs) {
this.hgs = hgs; // head+goals pointing to cells in cs
this.base = base; // heap where this starts
this.len = len; // length of heap slice
this.neck = neck; // first after the end of the head
this.xs = xs; // indexables in head
}
}
Loading