this repo has no description
1% RUNS ON mzn20_fd
2% RUNS ON mzn-fzn_fd
3% RUNS ON mzn20_fd_linear
4% RUNS ON mzn20_mip
5% WHO OWNS THE ZEBRA?
6%
7% This is a puzzle which has been circulating the net. There are a couple
8% different versions out there which try to be a little more politically
9% correct but are essentially the same problem.
10% 1. There are five houses, each of a different color and inhabited by
11% men of different nationalities, with different pets, drinks,
12% and cigarettes.
13% 2. The Englishman lives in the red house.
14% 3. The Spaniard owns the dog.
15% 4. Coffee is drunk in the green house.
16% 5. The Ukrainian drinks tea.
17% 6. The green house is immediately to the right of the ivory house.
18% 7. The Old Gold smoker owns snails.
19% 8. Kools are smoked in the yellow house.
20% 9. Milk is drunk in the middle house.
21% 10. The Norwegian lives in the first house on the left.
22% 11. The man who smokes Chesterfields lives in the house next to the
23% man with the fox.
24% 12. Kools are smoked in the house next to the house where the horse is
25% kept.
26% 13. The Lucky Strike smoker drinks orange juice.
27% 14. The Japanese smoke Parliaments.
28% 15. The Norwegian lives next to the blue house.
29% NOW, who drinks water? And who owns the zebra?
30
31% MiniZinc Version
32% Peter Stuckey September 30 2006
33
34include "globals.mzn";
35
36%enum Nationalities = { English, Spanish, Ukrainian, Norwegian, Japanese };
37set of int: Nationalities = 0..4;
38int: English = 0;
39int: Spanish = 1;
40int: Ukrainian = 2;
41int: Norwegian = 3;
42int: Japanese = 4;
43%enum Colours = { Red, Green, Ivory, Yellow, Blue };
44set of int: Colours = 0..4;
45int: Red = 0;
46int: Green = 1;
47int: Ivory = 2;
48int: Yellow = 3;
49int: Blue = 4;
50%enum Animals = { Dog, Fox, Horse, Zebra, Snails };
51set of int: Animals = 0..4;
52int: Dog = 0;
53int: Fox = 1;
54int: Horse = 2;
55int: Zebra = 3;
56int: Snails = 4;
57%enum Drinks = { Coffee, Tea, Milk, OrangeJuice, Water };
58set of int: Drinks = 0..4;
59int: Coffee = 0;
60int: Tea = 1;
61int: Milk = 2;
62int: OrangeJuice = 3;
63int: Water = 4;
64%enum Cigarettes = { OldGold, Kools, Chesterfields, LuckyStrike,
65% Parliaments } ;
66set of int: Cigarettes = 0..4;
67int: OldGold = 0;
68int: Kools = 1;
69int: Chesterfields = 2;
70int: LuckyStrike = 3;
71int: Parliaments = 4;
72
73set of int: Houses = 1..5;
74
75array[Nationalities] of var Houses: nation;
76array[Colours] of var Houses: colour;
77array[Animals] of var Houses: animal;
78array[Drinks] of var Houses: drink;
79array[Cigarettes] of var Houses: smoke;
80
81predicate nextto(var Houses:h1, var Houses:h2) =
82 h1 == h2 + 1 \/ h2 == h1 + 1;
83
84predicate rightof(var Houses:h1, var Houses:h2) =
85 h1 == h2 + 1;
86
87predicate middle(var Houses:h) = h == 3;
88
89predicate left(var Houses:h) = h = 1;
90
91constraint
92 alldifferent(nation) /\
93 alldifferent(colour) /\
94 alldifferent(animal) /\
95 alldifferent(drink) /\
96 alldifferent(smoke) /\
97 nation[English] == colour[Red] /\
98 nation[Spanish] == animal[Dog] /\
99 drink[Coffee] == colour[Green] /\
100 nation[Ukrainian] == drink[Tea] /\
101 colour[Green] `rightof` colour[Ivory] /\
102 smoke[OldGold] == animal[Snails] /\
103 smoke[Kools] == colour[Yellow] /\
104 middle(drink[Milk]) /\
105 left(nation[Norwegian]) /\
106 smoke[Chesterfields] `nextto` animal[Fox] /\
107 smoke[Kools] `nextto` animal[Horse] /\
108 smoke[LuckyStrike] == drink[OrangeJuice] /\
109 nation[Japanese] == smoke[Parliaments] /\
110 nation[Norwegian] `nextto` colour[Blue];
111
112solve satisfy;
113
114output [
115 "zebra:\n",
116 "nation = [",
117 show(nation[0]), ", ",
118 show(nation[1]), ", ",
119 show(nation[2]), ", ",
120 show(nation[3]), ", ",
121 show(nation[4]), "]\n",
122 "colour = [",
123 show(colour[0]), ", ",
124 show(colour[1]), ", ",
125 show(colour[2]), ", ",
126 show(colour[3]), ", ",
127 show(colour[4]), "]\n",
128 "animal = [",
129 show(animal[0]), ", ",
130 show(animal[1]), ", ",
131 show(animal[2]), ", ",
132 show(animal[3]), ", ",
133 show(animal[4]), "]\n",
134 "drink = [",
135 show(drink[0]), ", ",
136 show(drink[1]), ", ",
137 show(drink[2]), ", ",
138 show(drink[3]), ", ",
139 show(drink[4]), "]\n",
140 "smoke = [",
141 show(smoke[0]), ", ",
142 show(smoke[1]), ", ",
143 show(smoke[2]), ", ",
144 show(smoke[3]), ", ",
145 show(smoke[4]), "]\n"
146];