Einstein’s Riddle (also known as the Zebra Puzzle or the Five Houses Puzzle) is one of the most famous logic puzzles in the world.
Popular legend claims that it was created by Albert Einstein when he was a child (or a young student), often accompanied by the assertion that only 2% of the world’s population can solve it in their head. Another common attribution is to mathematician and author Lewis Carroll (author of Alice’s Adventures in Wonderland). However, there is no documented historical evidence from Einstein’s or Carroll’s lifetime to support their authorship. The earliest known published version appeared on December 17, 1962, in Life International magazine.
Despite the “2%” myth, the reality is that the puzzle does not require superhuman abilities, just deductive logical reasoning, data structuring, and patience.
Formal problem description
Imagine a street with 5 consecutive houses in a row (numbered 1 to 5 from left to right). Each house has the following properties:
There are 5 houses of 5 different colors: Yellow, Blue, Red, Green, and White.
In each house lives a person of a different nationality: Norwegian, Dane, Brit, German, and Swede.
Each owner drinks a specific beverage: Water, Tea, Milk, Coffee, and Beer.
Each owner smokes a specific brand of cigars: Dunhill, Blend, Pall Mall, Prince, and BlueMaster.
Each owner keeps a different pet: Cat, Horse, Bird, Fish, and Dog.
No two owners share the same nationality, house color, beverage, cigar brand, or pet.
To make the correct assignment, we are given the following 15 clues:
The Norwegian lives in the first house.
The person living in the center house drinks milk.
The owner of the yellow house smokes Dunhill.
The green house’s owner drinks coffee.
The Dane drinks tea.
The German smokes Prince.
The Swede keeps a dog as a pet.
The owner who smokes BlueMaster drinks beer.
The person who smokes Pall Mall rears a bird.
The green house is immediately to the left of the white house.
The British person lives in the red house.
The person who smokes Blend lives next to the person who keeps a cat.
The person who keeps a horse lives next to the person who smokes Dunhill.
The person who smokes Blend has a neighbor who drinks water.
The Norwegian lives next to the blue house.
The decisive question to answer is: Who owns the fish?
Do you dare to solve it logically before taking on the model?
Solution to the challenge
Solving the riddle yields the following unique assignment matrix:
Category
House 1
House 2
House 3
House 4
House 5
Nationality
Norwegian
Dane
Brit
German
Swede
Color
Yellow
Blue
Red
Green
White
Beverage
Water
Tea
Milk
Coffee
Beer
Cigar
Dunhill
Blend
Pall Mall
Prince
BlueMaster
Pet
Cat
Horse
Bird
Fish
Dog
Result: The owner of the fish is the German, who lives in House 4 (green house, drinks coffee, and smokes Prince).
This puzzle can be formulated as a binary linear optimization model. Do you dare to try it?
To solve Einstein’s Riddle systematically and automatically, we can formulate it as a binary linear optimization model.
Sets of indices
\(\mathcal{H} = \{1, 2, 3, 4, 5\}\): Set of houses (positions from left to right).
\(\mathcal{K} = \{\text{Nationality}, \text{Color}, \text{Beverage}, \text{Cigar}, \text{Pet}\}\): Set of categories.
\(\mathcal{I}_k\): Set of elements within category $k \in \mathcal{K}$, yielding the following index subsets:
\(x_{hki} = 1\) if house $h \in \mathcal{H}$ is assigned attribute $i \in \mathcal{I}_k$ of category $k \in \mathcal{K}$, and $0$ otherwise.
Since we are solving a logical feasibility problem (finding a unique valid assignment), the objective function can be any arbitrary function—for instance, a constant.
Objective function
\[\min z = 0\]
Now we define the rules and clues of the puzzle as linear constraints:
Each house has exactly one attribute from each category, and each attribute belongs to exactly one house:
\[\displaystyle \sum_{i \in \mathcal{I}_k} x_{hki} = 1 \quad \forall k \in \mathcal{K}, \; h \in \mathcal{H}\] \[\displaystyle \sum_{h \in \mathcal{H}} x_{hki} = 1 \quad \forall k \in \mathcal{K}, \; i \in \mathcal{I}_k\]
Would you like to keep exploring the world of Operations Research? Discover more posts on the topic here.
If you found this useful, please cite this as:
Martín-Campo, F. Javier (May 2026). Einstein’s Riddle. https://www.fjmartincampo.com/blog/2026/einsteinpuzzle/.
or as a BibTeX entry:
@misc{martín-campo2026einstein-s-riddle,title={Einstein's Riddle},author={Martín-Campo, F. Javier},year={2026},month={May},url={https://www.fjmartincampo.com/blog/2026/einsteinpuzzle/}}
Enjoy Reading This Article?
Here are some more articles you might like to read next: