Code:
solve(WaterDrinker, ZebraOwner) :-
%% There are five houses.
Street = [[ C1, N1, P1, D1, S1 ],
[ C2, N2, P2, D2, S2 ],
[ C3, N3, P3, D3, S3 ],
[ C4, N4, P4, D4, S4 ],
[ C5, N5, P5, D5, S5 ]],
%% The Englishman lives in the red house.
member([red, english, _, _, _], Street),
%% The Spaniard owns the dog.
member([_, spaniard, dog, _, _], Street),
%% Coffee is drunk in the green house.
member([green, _, _, coffee, _], Street),
%% The Ukrainian drinks tea.
member([_, ukranian, _, tea, _], Street),
%% The green house is immediately to the right of the ivory house.
right_of([green, _, _, _, _], [ivory, _, _, _, _], Street),
%% The Old Gold smoker owns snails.
member([_, _, snails, _, old_gold], Street),
%% Kools are smoked in the yellow house.
member([yellow, _, _, _, kools], Street),
%% Milk is drunk in the middle house.
D3 = milk,
%% The Norwegian lives in the first house.
N1 = norwegian,
%% The man who smokes Chesterfields lives in the house next to the man with the fox.
next_to([_, _, _, _, chesterfields], [_, _, fox, _, _], Street),
%% Kools are smoked in the house next to the house where the horse is kept.
next_to([_, _, _, _, kools], [_, _, horse, _, _], Street),
%% The Lucky Strike smoker drinks orange juice.
member([_, _, _, orange_juice, lucky_strike], Street),
%% The Japanese smokes Parliaments.
member([_, japanese, _, _, parliaments], Street),
%% The Norwegian lives next to the blue house.
next_to([blue, _, _, _, _], [_, norwegian, _, _, _], Street),
%% now, solutions:
member([_, WaterDrinker, _, water, _], Street),
member([_, ZebraOwner, zebra, _, _], Street).
right_of(E1, E2, [E2, E1 | _]).
right_of(E1, E2, [_|T]) :-
right_of(E1, E2, T).
next_to(E1, E2, L) :-
right_of(E1, E2, L);
right_of(E2, E1, L).
Bookmarks