3.7.277. Zebra puzzle
modelling: zebra puzzle
A constraint that can be used for modelling the zebra puzzle problem.
Here is the first known publication of that puzzle quoted in italic from Life International, December 17, 1962:
There are five houses.
The Englishman lives in the red house.
The Spaniard owns the dog.
Coffee is drunk in the green house.
The Ukrainian drinks tea.
The green house is immediately to the right of the ivory house.
The Old Gold smoker owns snails.
Kools are smoked in the yellow house.
Milk is drunk in the middle house.
The Norwegian lives in the first house.
The man who smokes Chesterfields lives in the house next to the man with the fox.
Kools are smoked in the house next to the house where the horse is kept.
The Lucky Strike smoker drinks orange juice.
The Japanese smokes Parliaments.
The Norwegian lives next to the blue house.
Now, who drinks water? Who owns the zebra?
In the interest of clarity, it must be added that each of the five houses is painted a different colour,
and their inhabitants are of different national extractions,
own different pets,
drink different beverages and
smoke different brands of American cigarettes.
In statement 6, right refers to the reader's right.
A first model involves constraints with variables in their tables
(i.e., the table of an constraint corresponds to its second argument).
It consists of creating for each house () five variables
, , , ,
respectively corresponding to the colour of house ,
the nationality of the person leaving in house ,
the preferred pet of the person leaving in house ,
the preferred beverage of the person leaving in house ,
the preferred brand of American cigarettes of the person leaving in house .
We first state the following five constraints
on these variables for expressing that colours, nationalities, pets, beverages,
and brands of American cigarettes are distinct:
,
,
,
,
.
Now observe that most statements link two specific attributes
(e.g.,Β The Englishman lives in the red house). Consequently,
in order to ease the encoding of such statements in term of constraints,
we will first create for each attribute a variable that indicates the house
where an attribute occurs. For instance, for the statement
The Englishman lives in the red house we will create two variables
which respectively indicate in which house the Englishman lives and
which house is red. We now create all the variables attached to each
class of attributes.
For each possible colour
we create a variable that corresponds to the index of the house having this colour.
For each variable , an constraint links it
to the variables giving the colour of each house:
, , , , ,
,
,
,
,
.
Note that we can replace the five previous constraints by the following
constraint:
For each possible nationality
we create a variable that corresponds to the index of the house where the person with this nationality lives.
For each variable , an constraint links it
to the variables giving the nationality associated with each house:
, , , , ,
,
,
,
,
.
Again we can replace the five previous constraints by the following
constraint:
For each possible preferred pet
we create a variable that corresponds to the index of the house where the person that prefers this pet lives.
For each variable , an constraint links it
to the variables giving the preferred pet of each house:
, , , , ,
,
,
,
,
.
Again we can replace the five previous constraints by the following
constraint:
For each possible preferred beverage
we create a variable that corresponds to the index of the house where the person that prefers this beverage lives.
For each variable , an constraint links it
to the variables giving the preferred beverage of each house:
, , , , ,
,
,
,
,
.
Again we can replace the five previous constraints by the following
constraint:
For each possible preferred brand of American cigarettes
we create a variable that corresponds to the index of the house where the person that prefers this brand lives.
For each variable , an constraint links it
to the variables giving the preferred brand of American cigarettes of each house:
, , , , ,
,
,
,
,
.
Again we can replace the five previous constraints by the following
constraint:
Finally we state one constraint for each statement from 2 to 15:
Β (the Englishman lives in the red house).
Β (the Spaniard owns the dog).
Β (coffee is drunk in the green house).
Β (the Ukrainian drinks tea).
Β (the green house is immediately to the right of the ivory house).
Β (the Old Gold smoker owns snails).
Β (kools are smoked in the yellow house).
Β (milk is drunk in the middle house).
Β (the Norwegian lives in the first house).
Β (the man who smokes Chesterfields lives in the house next to the man with the fox).
Β (kools are smoked in the house next to the house where the horse is kept).
Β (the Lucky Strike smoker drinks orange juice).
Β (the Japanese smokes Parliaments).
Β (the Norwegian lives next to the blue house).
Now note that variables , , , , () do not occur
at all within the constraints encoding statements 2 to 15. Consequently they can be removed,
as long as we replace the five constraints on these
variables by the following constraints:
,
,
,
,
.
In our experience, when confronted for the first time to this puzzle, a lot of people come up with
the model that associates to each house () five variables , , , ,
that describe the attributes of the person living in house . However it is difficult to directly express the
constraints according to these variables and the second model which associates to each attribute a variable
that gives the corresponding house is more convenient for expressing the constraints.