1:-module(lion_unicorn, []).    2
    3:- use_module(pac(basic)).    4:- use_module(zdd('zdd-array')).    5:- use_module(zdd(zdd)).    6:- use_module(pac(op)).    7
    8% ?- time(solve_lion_uncorn_puzzle_in_dnf(Ans)).
    9%@ % 8,097,097 inferences, 0.697 CPU in 0.717 seconds (97% CPU, 11618669 Lips)
   10%@ Ans = today(thu) .
   11%@ % 8,095,685 inferences, 0.744 CPU in 0.804 seconds (92% CPU, 10886331 Lips)
   12%@ Ans = today(thu) .
   13
   14solve_lion_uncorn_puzzle_in_dnf(Ans):-
   15	build_puzzle_prop(Prop),
   16	( zdd X<< dnf(Prop), zmod:zdd_find(=(today(_)), X, Ans) ).
   17
   18%
   19day_of_week([mon, tue, wed, thu, fri, sat, sun]).
   20%
   21liar_mode_list(unicorn, [1, 1, 1, 0, 0, 0, 1]).
   22liar_mode_list(lion,    [0, 0, 0, 1, 1, 1, 1]).
   23%
   24today(D):- day_of_week(Ds), member(D, Ds).
   25
   26% ?- yesterday(Y,T).
   27yesterday(Y, T):- day_of_week(Ds),
   28 	between(0, 6, J),
   29 	between(0, 6, I),
   30 	I is (J-1) mod 7,
   31 	nth0(J, Ds, T),
   32 	nth0(I, Ds, Y).
   33
   34% ?- liar(W, D).
   35liar(Who, D):- day_of_week(Ds),
   36	  liar_mode_list(Who, M),
   37	  between(0, 6, I),
   38	  nth0(I, M, 0),
   39	  nth0(I, Ds, D).
   40
   41% ?- build_puzzle_prop(_Prop), (zdd X<< dnf(_Prop), sets(X, _S), {length(_S, C0)}, card(X, C), psa(X)).
   42build_puzzle_prop(Props):-
   43	prop_group(today, Tod),
   44	prop_group(day_dependent_truth, Deps),
   45	prop_group(liar, Liar),
   46	Props = (*(Deps) * +(Tod) * *(Liar)).
   47
   48% ?- prop_group(today, T).
   49prop_group(today, TDs):-!, findall(today(D), today(D), TDs).
   50
   51% ?- prop_group(yesterday, Y), length(Y, N).
   52prop_group(yesterday, YDay):-!, findall(yesterday(Y, T), yesterday(Y, T), YDay).
   53
   54% ?- prop_group(liar, Y), length(Y, N), maplist(writeln, Y).
   55prop_group(liar, LiarProps):-!,
   56	findall(X,
   57		  (	today(D),
   58			member(Who, [lion, unicorn]),
   59			(	liar(Who, D), X = liar(Who, D)
   60			;	\+ liar(Who, D), X = -liar(Who, D)
   61			)
   62		  ),
   63		LiarProps).
   64
   65% ?- prop_group(day_dependent_truth, _Deps), maplist(writeln, _Deps).
   66%@ today(tue)->liar(lion,tue)== -liar(lion,mon)
   67%@ today(tue)->liar(unicorn,tue)== -liar(unicorn,mon)
   68%@ today(wed)->liar(lion,wed)== -liar(lion,tue)
   69%@ today(wed)->liar(unicorn,wed)== -liar(unicorn,tue)
   70%@ today(thu)->liar(lion,thu)== -liar(lion,wed)
   71%@ today(thu)->liar(unicorn,thu)== -liar(unicorn,wed)
   72%@ today(fri)->liar(lion,fri)== -liar(lion,thu)
   73%@ today(fri)->liar(unicorn,fri)== -liar(unicorn,thu)
   74%@ today(sat)->liar(lion,sat)== -liar(lion,fri)
   75%@ today(sat)->liar(unicorn,sat)== -liar(unicorn,fri)
   76%@ today(sun)->liar(lion,sun)== -liar(lion,sat)
   77%@ today(sun)->liar(unicorn,sun)== -liar(unicorn,sat)
   78%@ today(mon)->liar(lion,mon)== -liar(lion,sun)
   79%@ today(mon)->liar(unicorn,mon)== -liar(unicorn,sun)
   80%@ true.
   81
   82prop_group(day_dependent_truth, Deps):-
   83	findall( today(D)->(liar(Who, D) == -liar(Who, Y)),
   84			(	yesterday(Y, D),
   85				member(Who, [lion, unicorn])
   86			),
   87			Deps)