🔴 Riddle #59 of 240
One hundred prisoners stand in a line, each wearing a black or white hat, each able to see only the hats in front of them. Starting from the back, each must call out "black" or "white"; a prisoner is freed if the call matches their own hat. They may agree on a strategy beforehand but cannot signal afterwards. How many can they guarantee to free?
Think about it first. When you're ready:
99 prisoners (all but the first)
The back prisoner calls the parity of black hats ahead of him; each later prisoner combines that call with the colours already named and the hats he sees to deduce his own, so 99 go free (checked by simulation).