The Einstein Puzzle is a logic puzzle that establishes a list
of conditions among 5 neighbours. There are five houses in five
different colors. In each house lives a person with a different
nationality. The five owners drink a certain type of beverage,
smoke a certain brand of cigar, and keep a certain pet. No owners
have the same pet, smoke the same brand of cigar or drink the
same beverage.
Question
Who owns the fish?
Hints
- The Brit lives in the red house.
- The Swede keeps dogs as pets.
- The Dane drinks tea.
- The green house is on the left of the white house.
- The green house’s owner drinks coffee.
- The person who smokes Pall Mall rears birds.
- The owner of the yellow house smokes Dunhill.
- The man living in the center house drinks milk.
- The Norwegian lives in the first house.
- The man who smokes Blends lives next to the one who keeps cats.
- The man who keeps the horse lives next to the man who smokes Dunhill.
- The owner who smokes Bluemasters drinks beer.
- The man who keeps the horse lives next to the man who smokes Dunhill.
- The German smokes Prince.
- The Norwegian lives next to the blue house.
- The man who smokes Blends has a neighbor who drinks water.
Assumptions
- The owner is the resident of each house.
- One of the residents owns the fish.
- The term neighbor in the last hint refers only to a directly adjacent neighbor.
- The houses are on the same side of the street.
- They are next to each other, and are ordered from left to right as you face them.
To model this problem, we created 150 variables to capture
states and possible combinations. From these 150 variables,
we designed rules that comply with the conditions specified
by the puzzle. These rules were represented by 1300 clauses,
categorised into several sections.
Simple Rules
2-clauses to represent specified conditions that bind 2
properties.
(i.e. If person P is Dane, then person P drinks tea.)
Proximity Rules
Clauses representing implications between states (ownership of
traits) and positions of the houses.
(i.e. If person P is in first house and has green house, then
if person Q is in second house, then person Q has white house.)
Exactly-1 Rules
Clauses that limit the ownership of each category of traits
for a single owner.
(i.e. If person P is in the first house, then person P cannot
be in the second to fifth house, etc.)
Unicity Rules
Clauses that define the exclusivity of traits between the owners.
(i.e. If person P is in the first house, then person Q is not
in the first house, etc.)
These set of literals and clauses were written in Conjunctive
Normal Form (CNF) and used with our solvers to solve the puzzle.