fork(9) 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. zebra(Owns, HS):- % color,nation,pet,drink,smokes
  8. HS = [h(_,norwegian,_,_,_),_,h(_,_,_,milk,_),_,_],
  9. select([h(red,english,_,_,_),h(_,swede,dog,_,_),h(_,dane,_,tea,_),
  10. h(_,german,_,_,prince)], HS),
  11. select([h(_,_,birds,_,pallmall),h(yellow,_,_,_,dunhill),
  12. h(_,_,_,beer,bluemaster)], HS),
  13. left_of( h(green,_,_,coffee,_),h(white,_,_,_,_), HS),
  14. next_to( h(_,_,_,_,dunhill),h(_,_,horse,_,_), HS),
  15. next_to( h(_,_,_,_,blend), h(_,_,cats, _,_), HS),
  16. next_to( h(_,_,_,_,blend), h(_,_,_,water,_), HS),
  17. next_to( h(_,norwegian,_,_,_), h(blue,_,_,_,_), HS),
  18. member( h(_,Owns,zebra,_,_), HS).
  19.  
  20. main :-
  21. zebra(Who, HS), maplist(writeln,HS), nl, write(Who), nl, nl, fail
  22. ;
  23. write('No more solutions.').
Success #stdin #stdout 0.02s 6204KB
stdin
main.
stdout
h(yellow, norwegian, cats, water, dunhill)
h(blue, dane, horse, tea, blend)
h(red, english, birds, milk, pallmall)
h(green, german, zebra, coffee, prince)
h(white, swede, dog, beer, bluemaster)

german

No more solutions.