Puzzles/Logic puzzles/Infinite Hats/Solution

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Puzzles | Logic puzzles | Infinite Hats | Solution


All but the last one can tell what colour hat he/she is wearing.

First, they agree on a way for the last person to count the number of hats in front of himself. An excellent way is for him (we'll assume it's a guy) to count the number of red hats. Then, he'll guess the colour of his hat based on that count: He'll say "red" if it's odd or "blue" if it's even.

Then, as each person goes down the row, she (to be fair) looks at the hats in front of her. She knows if there is an even number of red hats *including her own*, and can see how many red hats are in front of her. If there are an even number in front of her, and there are an even number including her own, then hers must be blue! When she answers with the colour of her hat, then the person in front of her will know whether to adjust the current count of red hats, and the puzzle can go on to completion.

Another way to look at the solution is counting in base 2, mod 2. Red hats are 1s and Blue hats are 0s. The last person in the row tells what the sum of everyone's hats in front of him is. He announces "Red" (Total = 1) or "Blue" (Total = 0). Then, the next person sums up the hats in front of her, and gets Total-In-Front-Of-Me. She knows that Total - Total-In-Front-Of-Me (mod 2) = Color-Of-My-Hat, and can announce her hat colour. The person in front of *her* can then figure out NewTotal = Total - Color-Of-Her-Hat (mod 2), and work out what colour his hat is, etc...