Download zip Select Archive Format
Name Last Update history
File dir css Loading commit data...
File txt 8queens-bt.xq Loading commit data...
File txt 8queens-bt2.xq Loading commit data...
File txt 8queens.pro Loading commit data...
File txt 8queens.xq Loading commit data...
File txt 8queens.xsl Loading commit data...
File txt README.md Loading commit data...
File txt backtrack.xq Loading commit data...
File txt backtracking.xpr Loading commit data...
File txt puzzle-bq.xq Loading commit data...
File txt puzzle.pro Loading commit data...
File txt puzzle.xq Loading commit data...
File txt slides.dita Loading commit data...
File txt tabundle.html Loading commit data...

README.md

Prolog receipes

$ swipl -s 8queens.pro
% /home/vdv/projects/lab/presentations/backtracking/8queens.pro compiled 0.00 sec, 6 clauses
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.6.6)
Copyright (c) 1990-2013 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- 

?- forall(queens(8, Queens), write(Queens)).
[1,5,8,6,3,7,2,4][1,6,8,3,7,4,2,5][1,7,4,6,8,2,5,3][1,7,5,8,2,4,6,3][2,4,6,8,3,1,7,5][2,5,7,1,3,8,6,4][2,5,7,4,1,8,6,3][2,6,1,7,4,8,3,5][2,6,8,3,1,4,7,5][2,7,3,6,8,5,1,4][2,7,5,8,1,4,6,3][2,8,6,1,3,5,7,4][3,1,7,5,8,2,4,6][3,5,2,8,1,7,4,6][3,5,2,8,6,4,7,1][3,5,7,1,4,2,8,6][3,5,8,4,1,7,2,6][3,6,2,5,8,1,7,4][3,6,2,7,1,4,8,5][3,6,2,7,5,1,8,4][3,6,4,1,8,5,7,2][3,6,4,2,8,5,7,1][3,6,8,1,4,7,5,2][3,6,8,1,5,7,2,4][3,6,8,2,4,1,7,5][3,7,2,8,5,1,4,6][3,7,2,8,6,4,1,5][3,8,4,7,1,6,2,5][4,1,5,8,2,7,3,6][4,1,5,8,6,3,7,2][4,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

?- trace,forall(queens(8, Queens), write(Queens)).
^  Call: (7) forall(queens(8, _G202), write(_G202)) ? creep
   Call: (8) queens(8, _G202) ? creep
   Call: (9) queens(8, [], _G202) ? creep
   Call: (10) between(1, 8, _G374) ? creep
   Exit: (10) between(1, 8, 1) ? creep
   Call: (10) attack([], 1) ? creep
   Call: (11) lists:member(1, []) ? creep
   Fail: (11) lists:member(1, []) ? creep
   Redo: (10) attack([], 1) ? creep
   Call: (11) same_diag([], [], 1) ? creep
   Fail: (11) same_diag([], [], 1) ? creep
   Fail: (10) attack([], 1) ? creep
   Redo: (9) queens(8, [], _G202) ? creep
   Call: (10) lists:append([], [1], _G377) ? creep
   Exit: (10) lists:append([], [1], [1]) ? creep
   Call: (10) length([1], _G376) ? creep
   Exit: (10) length([1], 1) ? creep
   Call: (10) 1<8 ? creep
   Exit: (10) 1<8 ? creep
   Call: (10) queens(8, [1], _G202) ? creep
   Call: (11) between(1, 8, _G377) ? creep
   Exit: (11) between(1, 8, 1) ? creep
   Call: (11) attack([1], 1) ?