House Puzzle

From the data provided below, determine who drinks water and who owns the zebra.

There are five houses each of a different color and inhabited by men of different nationalities, with different pets, drinks, and brands of cigarettes.

  1. The Englishman lives in the red house.
  2. The Spaniard owns the dog.
  3. Coffee is drunk in the green house.
  4. The Ukranian drinks tea.
  5. The green house is immediately to the right (your right) of the ivory house.
  6. The Winston smoker owns snails.
  7. Kools are smoked in the yellow house.
  8. Milk is drunk in the middle house.
  9. The Norwegian lives in the first house on the left.
  10. The man who smokes Chesterfields lives in the house next to the man with the fox.
  11. Kools are smoked in the house next to the house where the horse is kept.
  12. The Lucky Strike smoker drinks orange juice.
  13. The Japanese smokes Parliaments.
  14. The Norwegian lives next to the blue house.
solve(ZebraOwner, WaterDrinker):-
  queries(Houses, ZebraOwner, WaterDrinker).

  house(A, Houses), colour(A, red), nationality(A, english),         /*  1 */
  house(B, Houses), nationality(B, spaniard), pet(B, dog),           /*  2 */
  house(C, Houses), colour(C, green), drink(C, coffee),              /*  3 */
  house(D, Houses), nationality(D, ukranian), drink(D, tea),         /*  4 */
  immed_to_right(Houses, E, F), colour(E, green), colour(F, ivory),  /*  5 */
  house(G, Houses), smoke(G, winston), pet(G, snails),               /*  6 */
  house(H, Houses), smoke(H, kools), colour(H, yellow),              /*  7 */
  middle(Houses, I), drink(I, milk),                                 /*  8 */
  first(Houses, J), nationality(J, norwegian),                       /*  9 */
  next_to(Houses, K, L), smoke(K, chesterfields), pet(L, fox),       /* 10 */
  next_to(Houses, M, N), smoke(M, kools), pet(N, horse),             /* 11 */
  house(O, Houses), smoke(O, luckystrike), drink(O, orangejuice),    /* 12 */
  house(P, Houses), nationality(P, japanese), smoke(P, parliaments), /* 13 */
  next_to(Houses, Q, R), nationality(Q, norwegian), colour(R, blue). /* 14 */

queries(Houses, ZebraOwner, WaterDrinker):-
  house(X, Houses), pet(X, zebra), nationality(X, ZebraOwner), % japanese
  house(Y, Houses), drink(Y, water), nationality(Y, WaterDrinker). % norwegian

colour(house(C,_,_,_,_), C).
nationality(house(_,N,_,_,_), N).
pet(house(_,_,P,_,_), P).
drink(house(_,_,_,D,_), D).
smoke(house(_,_,_,_,S), S).

first(houses(X,_,_,_,_), X).

middle(houses(_,_,X,_,_), X).

immed_to_right(houses(L,R,_,_,_), R, L).
immed_to_right(houses(_,L,R,_,_), R, L).
immed_to_right(houses(_,_,L,R,_), R, L).
immed_to_right(houses(_,_,_,L,R), R, L).

next_to(Xs, X, Y):-
  immed_to_right(Xs, X, Y).
next_to(Xs, X, Y):-
  immed_to_right(Xs, Y, X).

house(X, houses(X,_,_,_,_)).
house(X, houses(_,X,_,_,_)).
house(X, houses(_,_,X,_,_)).
house(X, houses(_,_,_,X,_)).
house(X, houses(_,_,_,_,X)).

LPA Index     Home Page