Zebra puzzle: Difference between revisions

Content deleted Content added
WillNess (talk | contribs)
→‎Direct rule by rule translation: add white space to code for legibility
WillNess (talk | contribs)
Line 5,081: Line 5,081:
attrs( H, [N-V | R]) :- memberchk( N-X, H), X = V, (R = [] -> true ; attrs( H, R)).
attrs( H, [N-V | R]) :- memberchk( N-X, H), X = V, (R = [] -> true ; attrs( H, R)).


in( HS, Attrs) :- member( H, HS), attrs( H, Attrs).
in( HS, Attrs) :- member( H, HS), attrs( H, Attrs).
in( HS, G, AttrsL) :- call( G, Args, HS), maplist( attrs, Args, AttrsL).
in( G, HS, AttrsL) :- call( G, Args, HS), maplist( attrs, Args, AttrsL).


left_of( [A,B], HS) :- append( _, [A,B | _], HS).
left_of( [A,B], HS) :- append( _, [A,B | _], HS).
Line 5,098: Line 5,098:
, [ nation-german, smoke-'Prince' ] % 14
, [ nation-german, smoke-'Prince' ] % 14
] ),
] ),
in( Houses, left_of, [[color -green ], [color -white ]]), % 5
in( left_of, Houses, [[color -green ], [color -white ]]), % 5
maplist( attrs, [C,A], [[drink -milk ], % 9
maplist( attrs, [C,A], [[drink -milk ], % 9
[nation-norwegian]]), % 10
[nation-norwegian]]), % 10
maplist( in( Houses, next_to),
maplist( in( next_to, Houses),
[ [[smoke -'Blend' ], [owns -cats ]] % 11
[ [[smoke -'Blend' ], [owns -cats ]] % 11
, [[owns -horse ], [smoke-'Dunhill' ]] % 12
, [[owns -horse ], [smoke-'Dunhill' ]] % 12
Line 5,121: Line 5,121:
german
german
No More Solutions
No More Solutions
% 250,927 inferences, 0.027 CPU in 0.027 seconds (100% CPU, 9240311 Lips)</lang>
% 235,165 inferences, 0.031 CPU in 0.040 seconds (78% CPU, 7537291 Lips)</lang>


===Alternative version===
===Alternative version===