fork download
  1. select([A|As],S):- select(A,S,S1),select(As,S1).
  2. select([],_).
  3.  
  4. next_to(A,B,C):- left_of(A,B,C) ; left_of(B,A,C).
  5. left_of(A,B,C):- append(_,[A,B|_],C).
  6.  
  7. puzzle(X, Houses) :- % color, territory, animal, drink, car
  8. Houses = [h(_, west, _, _, _), _, h(_, _, _, milk, _), _, _],
  9. select([h(red, tasmania, _, _, _),
  10. h(green, _, _, cocoa, _),
  11. h(yellow, _, _, _, ford)], Houses),
  12. select([h(_, queensland, wombat, _, _),
  13. h(_, nsw, _, eggnog, _),
  14. h(_, victoria, _, _, vw)], Houses),
  15. select([h(_, _, crocodile, _, oldsmobile),
  16. h(_, _, _, juice, mercedes)], Houses),
  17. left_of(h(ivory, _, _, _, _), h(green, _, _, _, _), Houses),
  18. next_to(h(_, _, _, _, chevrolet), h(_, _, devil, _, _), Houses),
  19. next_to(h(_, _, _, _, ford), h(_, _, platipus, _, _), Houses),
  20. next_to(h(_, west, _, _, _), h(blue, _, _, _, _), Houses),
  21. member(h(_, X, coala, _, _), Houses).
  22.  
  23. main :- puzzle(X, Houses), maplist(writeln, Houses), nl, nl, fail.
  24. main :- write('No more solutions.').
  25.  
Success #stdin #stdout #stderr 0.04s 6204KB
stdin
main.
stdout
h(yellow, west, devil, _G130, ford)
h(blue, nsw, platipus, eggnog, chevrolet)
h(red, tasmania, crocodile, milk, oldsmobile)
h(ivory, queensland, wombat, juice, mercedes)
h(green, victoria, coala, cocoa, vw)


No more solutions.
stderr
Warning: /home/dPlQcb/prog.pl:23:
	Singleton variables: [X]

true.