Hundred prisoners and coloured hats
product-puzzle case · difficulty 4/5 · 15 minutes · other
Prompt
100 prisoners stand in a line, each wearing a red or blue hat chosen at random. Each prisoner can see the hats of everyone in front of him, but not his own or those behind him. Starting from the back, each prisoner must call out "red" or "blue" for his own hat, and everyone hears the answers. They can agree on a strategy beforehand. How can they make sure that as many as possible survive?
Context
A classic interview puzzle. Core idea: The last person uses parity (even/odd) of red hats to signal the rest. Talk through your reasoning; the interviewer cares as much about structure as about the answer.
Clarifying questions
- Can they agree on a strategy?
- Yes. They hear every answer, can say only one word, and can agree a plan before the hats are placed.
Recommendation
**Answer:** At least 99 of the 100 prisoners are guaranteed to survive, and the one at the back survives with probability 1/2. **Why:** One announcement can encode a parity of the whole line, and every later prisoner can use subtraction, as each correct answer keeps the running parity consistent.
Risks
- Having each prisoner guess the colour of the hat in front of him
- Forgetting that later prisoners must adjust for the answers already given
Next steps
- Solve the 10-colour version by working modulo 10
- Explain why no strategy can guarantee all 100 survive