/* Zebra puzzle brute force approach in Picat. Based on SetlX's example zebra-brute-force.stlx """ This program solves the zebra puzzle, which is stated below. 01. There are five houses. Each house is painted a different color, and their inhabitants are of different nationalities, own different pets, drink different beverages and smoke different brands of cigarettes. 02. The Englishman lives in the red house. 03. The Spaniard owns the dog. 04. Coffee is drunk in the green house. 05. The Ukrainian drinks tea. 06. The green house is immediately to the right of the ivory house. 07. The Gold smoker owns snails. 08. Kools are smoked in the yellow house. 09. Milk is drunk in the middle house. 10. The Norwegian lives in the first house. 11. The man who smokes West lives in the house next to the man with the fox. 12. Kools are smoked in a house next to the house where the horse is kept. 13. The man who smokes Luckies drinks orange juice. 14. The Japanese smokes Camel. 15. The Norwegian lives next to the blue house. Who drinks water? Who owns the zebra? """ Solution: colors: [3, 5, 4, 1, 2] nationalities: [3, 4, 2, 5, 1] drinks: [5, 2, 3, 4, 1] pet: [4, 3, 1, 2, 5] cigarettes: [3, 1, 2, 4, 5] [water = 1,zebra = 5] This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. main => go. go => println(zebraPuzzle()), nl. % Is house h1 right of house h2? isRightOf(H1,H2) => H1 == H2 + 1. % Is house h1 next to house h2? nextTo(H1,H2) => abs(H1 - H2) == 1. % Compute the set of all solutions to the zebraPuzzle. zebraPuzzle = Result => First = 1, Middle = 3, Result1 = [], Orderings = permutations(1..5), foreach ([Red, Green, Ivory, Yellow, Blue] in Orderings) if isRightOf(Green, Ivory) then foreach ([English, Spaniard, Ukrainian, Japanese, Norwegian] in Orderings) if English == Red, Norwegian == First, nextTo(Norwegian, Blue) then foreach ([Coffee, Tea, Milk, Orange, Water] in Orderings) if Coffee == Green, Ukrainian == Tea, Milk == Middle then foreach ([Gold, Kools, West, Luckies, Camel] in Orderings) if Kools == Yellow, Luckies == Orange, Japanese == Camel then foreach ([Dog, Snails, Fox, Horse, Zebra] in Orderings) if Spaniard == Dog, Gold == Snails, nextTo(West, Fox), nextTo(Kools, Horse) then println("colors: "=[Red, Green, Ivory, Yellow, Blue]), println("nationalities: "=[English, Spaniard, Ukrainian, Japanese, Norwegian]), println("drinks: "=[Coffee, Tea, Milk, Orange, Water]), println("pet: "=[Dog, Snails, Fox, Horse, Zebra]), println("cigarettes: "=[Gold, Kools, West, Luckies, Camel]), Result1 := [water=Water, zebra=Zebra] end end end end end end end end end end, Result = Result1.