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
19day_of_week([mon, tue, wed, thu, fri, sat, sun]).
21liar_mode_list(unicorn, [1, 1, 1, 0, 0, 0, 1]).
22liar_mode_list(lion, [0, 0, 0, 1, 1, 1, 1]).
24today(D):- day_of_week(Ds), member(D, Ds).
25
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
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
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
49prop_group(today, TDs):-!, findall(today(D), today(D), TDs).
50
52prop_group(yesterday, YDay):-!, findall(yesterday(Y, T), yesterday(Y, T), YDay).
53
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
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)