@kuniaki.mukai posted a Prolog SAT solver solution to
the Lion and Unicorn riddle. Can this be further improved:
% ?- time(solve_lion_uncorn_puzzle_in_dnf(Ans)).
%@ % 8,188,821 inferences, 0.626 CPU in 0.647 seconds
(97% CPU, 13085762 Lips)
%@ Ans = today(thu) ;
%@ % 171 inferences, 0.004 CPU in 0.004 seconds (100% CPU, 47017 Lips)
%@ false.
A SAT solver is a computer program which aims to
solve the Boolean satisfiability problem. Using Boolean
modelling I only got that far:
yesterday(0,0,0,1,1,0).
yesterday(0,0,1,0,0,0).
yesterday(0,1,0,0,0,1).
yesterday(0,1,1,0,1,0).
yesterday(1,0,0,0,1,1).
yesterday(1,0,1,1,0,0).
yesterday(1,1,0,1,0,1).
lying_day(0,0,0,1).
lying_day(0,0,1,0).
lying_day(0,0,1,1).
lying_day(1,1,0,0).
lying_day(1,1,0,1).
lying_day(1,1,1,0).
solve_for(T1,T2,T3) :- yesterday(T1,T2,T3,Y1,Y2,Y3)
, contrary(lying_day(0,T1,T2,T3), lying_day(0,Y1,Y2,Y3))
, contrary(lying_day(1,T1,T2,T3), lying_day(1,Y1,Y2,Y3)).
contrary(S,T) :- \+ S, T.
contrary(S,T) :- S, \+ T.
And then:
?- time(solve_for(T1,T2,T3)).
% 32 inferences, 0.000 CPU in 0.000 seconds (0% CPU, Infinite Lips)
T1 = 1,
T2 = T3, T3 = 0 ;
% 17 inferences, 0.000 CPU in 0.000 seconds (0% CPU, Infinite Lips)
false.
What now, how to use a SAT Solver?