Puzzles solved with logic programming using SWI-Prolog language.
$ swipl -g solve -s farmer.pro
Replace farmer
with the desired puzzle.
$ swipl -s farmer.pro
?- solve(30, 74, Chickens, Cows).
% Chickens = 23,
% Cows = 7.
% Exit with Ctrl^C + e or halt.
$ swipl -s "../Layton/Curious Village/128-curious-lock.pro"
solve([A,B,C,D,E,F,G]), display_lock_nl([A,B,C,D,E,F,G]).
3 1
4 2 9
6 8
A = 3,
B = 4,
C = 6,
D = 2,
E = 1,
F = 9,
G = 8 ;
% press ; or space for more solutions
3 8
4 2 9
6 1
A = 3,
B = 4,
C = 6,
D = 2,
E = 8,
F = 9,
G = 1 .
% press . or enter to stop
See: Executing a query
At the end of each puzzle file there is a <examples>
section with example queries.
$ swipl
?- ["farmer.pro"]. % load file
?- make. % reload file
?- solve.
?- trace.
[trace] ?- solve(30, 74, Chickens, Cows).
% Call: (10) solve(30, 74, _51476, _51478) ? creep
% ...
% Exit: (10) solve(30, 74, 23, 7) ? creep
[trace] ?- notrace.
[debug] ?- nodebug.