/* Zebra ("Prolog version") in Picat. This is a port from the Prolog version http://www.anselm.edu/internet/compsci/faculty_staff/mmalita/HOMEPAGE/logic/zebra.txt """ There are 15 facts and 2 questions: Who has a zebra and who drinks water? 1) There are 5 colored houses in a row, each having an owner, which has an animal, a favorite cigarette, a favorite drink. 2) The English lives in the red house. 3) The Spanish has a dog. 4) They drink coffee in the green house. 5) The Ukrainian drinks tea. 6) The green house is next to the white house. 7) The Winston smoker has a serpent. 8) In the yellow house they smoke Kool. 9) In the middle house they drink milk. 10) The Norwegian lives in the first house from the left. 11) The Chesterfield smoker lives near the man with the fox. 12) In the house near the house with the horse they smoke Kool. 13) The Lucky Strike smoker drinks juice. 14) The Japanese smokes Kent. 15) The Norwegian lives near the blue house. We represent the houses as a list with 5 lists from left to right: Sol = [[Man, Animal, Cigarette, Drink, Color], [..],[..],[..],[..] ] """ Cf my CP version http://www.hakank.org/picat/zebra.pi This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. % import cp. main => go. go => zebra(Sol,Zebra, Water), foreach(H in Sol) println(H) end, println(zebra=Zebra), println(water=Water), nl. zebra(Sol,Zebra,Water) => Sol = new_list(5), % 1 member([english,_,_,_,red],Sol), % 2 member([spanish,dog,_,_,_],Sol), % 3 member([_,_,_,coffee,green],Sol), % 4 member([ukrainian,_,_,tea,_],Sol), % 5 right([_,_,_,_,green],[_,_,_,_,white], Sol), % 6 member([_,snake,winston,_,_],Sol), % 7 member([_,_,kool,_,yellow],Sol), % 8 Sol= [_,_,[_,_,_,milk,_],_,_], % 9 Sol= [[norwegian,_,_,_,_],_,_,_,_], % 10 next([_,_,chesterfield,_,_],[_,fox,_,_,_],Sol), % 11 next([_,_,kool,_,_],[_,horse,_,_,_], Sol), % 12 member([_,_,lucky,juice,_],Sol), % 13 member([japanese,_,kent,_,_],Sol), % 14 next([norwegian,_,_,_,_],[_,_,_,_,blue],Sol), % 15 member([_,_,_,water,_],Sol), % someone drinks water member([_,zebra,_,_,_],Sol), % someone has a zebra member([Zebra,zebra,_,_,_],Sol), % who has the zebra? member([Water,_,_,water,_],Sol). % who drinks water? % % Helper predicates from % http://www.anselm.edu/internet/compsci/faculty_staff/mmalita/HOMEPAGE/logic/bibmm.txt % right(X,Y,L) => append(_,[X,Y|_],L). next(X,Y,L) => right(X,Y,L) ; right(Y,X,L).