October 9, 2012

The zebra puzzle

[Note: In my version, there's a fish...]

There are five people of different nationalities living in five houses of different colours, drinking five different things, smoking five different cigars and keeping five different pets.

Nations: Brit, Dane, German, Norwegian, Swede
Houses: Blue, Green, Red, White, Yellow
Drinks: Beer, Coffee, Milk, Tea, Water
Cigars: Blue Master, Dunhill, Pall Mall, Prince, Blend (X)
Pets: Cat, Bird, Dog, Fish, Horse

These things we know:
  1. The British person lives in the red house.
  2. The Swede keeps dogs as pets.
  3. The Dane drinks tea.
  4. The green house is on the left of the white house.
  5. The green homeowner drinks coffee.
  6. The man who smokes Pall Mall keeps birds.
  7. The owner of the yellow house smokes Dunhill.
  8. The man living in the center house drinks milk.
  9. The Norwegian lives in the first house.
  10. The man who smokes Blend lives next to the one who keeps cats.
  11. The man who keeps the horse lives next to the man who smokes Dunhill.
  12. The man who smokes Bluemaster drinks beer.
  13. The German smokes Prince.
  14. The Norwegian lives next to the blue house.
  15. The man who smokes Blend has a neighbor who drinks water.
Question: who owns the fish?

It is sometimes claimed that only 2% of the people can solve this. If you think you are among this 2%, you can go away and figure out yourself. On the other hand, you really shouldn't give a shit if you can't. There's no universal measurement of human intelligence. If you are not good at solving puzzles like this, you might be much better at something else. Or maybe you are simply lazy...

Actually this is the kind of puzzle which is relatively simple to solve if you study mathematics or computer science. Well, maybe every puzzle is easier to solve for these two kinds of professionals, but like I said, intelligence is not necessarily about solving puzzles. All right, here comes the solution:

First of all, you should create a 5*5 table since there are five pieces in five different sets, so you will definitely need it to express the solution. The row header (first row) should be the numbers [1,2,3,4,5] or ['1. place' .. '5. place'], and the column header should be [Nation, Colour, Drink, Cigar, Pet].

Second, try to formalize the fifteen statements in a very concise way. For example, I used '=' for "in the same", '<' for "to the left", '>' for "to the right" and '><' for "next to". With this notation, the statements are:
  1. Brit = Red 
  2. Swede = Dog 
  3. Dane = Tea 
  4. Green < White 
  5. Green = Coffee 
  6. PallMall = Bird 
  7. Yellow = Dunhill 
  8. Milk = 3 
  9. Norwegian = 1 
  10. Blend >< Cat 
  11. Horse >< Dunhill 
  12. BlueMaster = Beer 
  13. German = Prince 
  14. Norwegian >< Blue 
  15. Blend >< Water
The way to solve the puzzle is to figure out how each statement limits the possibilities for each cell. For a start, you should write down every possibility into every cell. This is why I put those letters of the words in bold: you should use them! The cells of the first row should have 'BDGNS', those in the second should have 'BGRWY', and so on... 

Now you can start actually solving the puzzle. If you find out how a statement limits some possibilities, just strike through the letters which get ruled out, or erase them with a gum. You should start with statement 9: erase all but the N from the first column and the N itself from all the others in the row. (There's no Norwegian in the other houses!) Then you should go for statement 8, then... Well, now you should really try and figure it out yourself! This is the point when the whole thing becomes a crude and simple mental workout. 

Note: there are some statements which you have to use more than once! If you get lost, you should re-examine them one by one...

This puzzle is a very good illustration of a common general heuristic for problem solving: first of all you visualize and formalize the problem somehow, then you gather (and formalize) all the facts you know about it, then finally you can start narrowing down the "solution space" in order to find a good solution. 

Sometimes you need to find a new way to visualize and formalize! This is usually the most important pre-requisite of a scientific breakthrough...

No comments: