First of all… nowhere in the statement of the puzzle is there anything about prisoners having their life spared if they state the color of their hat correctly. So they all get one hour more of life by discussing… and THAT’S IT! Plus they get the satisfaction of knowing they have improved their odds of getting the puzzle solved.
So assuming they decide to try for the pure intellectual satisfaction of it (the puzzle does state, “is there a strategy that they can use that will improve their chances, and if so, what is it?”) - the answer is not as simple as Ray presents. The one white hat out of 30 example makes it seem simpler than it is. Prisoners must track the odd/even state as it goes along. Only #30 has the easy answer. Unfortunately, his easy answer makes it a 50/50 chance for himself. He MUST report the color of the odd number ahead of him. Piter is correct. This is a ROLLING parity bit. If only #10 has a white hat as in Tom’s example… pretty easy to track since it only swaps once. But if there are lots of white hats, every prisoner must make the computation of parity (ODD or EVEN) and keep track of it as it swaps back and forth. Not trivial as the single white hat example would lead one to believe.
Let’s take the worst case example - the hats alternate, 15 black and 15 white interleaved. Prisoner #30 is doomed. Whichever color he has, he will see an odd number of the other color, and must report that. That will always be wrong. We’ll give him a white hat. He says BLACK because he sees 15 black hats in front of him… an odd number of blacks.
So #29 thinks: #30 saw an odd number of blacks, I see 14 (EVEN), therefore I must have one of the black hats he saw. So #28 must track - #30 saw odd blacks, #29 KNOWS he has a black hat, therefore he must see an EVEN number of blacks. I (#28) still see an EVEN number of blacks, therefore I must not have one of them, and I must have a WHITE hat. So far so good, but #27 must have been tracking all this, because there’s no way for him to determine his own color, based solely on the color reported by the guy behind him. He must know that #30 said BLACK, meaning and odd number of blacks, #29 said BLACK meaning now there is an EVEN number of blacks, #28 said WHITE meaning an even number of blacks… and so it goes. Poor guys with low numbers… they must track the entire sequence, and compute right along with each of the couple dozen guys behind them what odd count is when it gets to each one, and what their answer means.
Look what they must track:
First guy to speak (#30) says BLACK, because he sees an odd number of blacks
Second guy (#29) says BLACK, because he sees an EVEN number of blacks so must have one of them.
Third guy (#28) has to remember that second guy said BLACK because the first guy saw odd, and the second guy saw EVEN. #28 still sees EVEN and says WHITE, because the guy before him (#29) said BLACK because he saw an EVEN number of blacks.
Fourth guy (#27) is already struggling. He knows that the guy before him said WHITE, but he has to remember what WHITE means in this string of answers. He must remember everything third guy remembered, plus add in his own knowledge. #27 must remember:
First guy said BLACK meaning ODD number of BLACKS in front of him; second guy said BLACK meaning now EVEN number of BLACKS in front of him; third guy said WHITE meaning there was an EVEN number, and now there is still an EVEN number of BLACKS so he can’t have one of them. I see an ODD number, therefore I must have one and say, “BLACK.”
Just in typing this I made 4 mistakes I had to correct, and I’m only on the fourth guy. Poor numbers 1 through 6. They got lost shortly after this started - and are now back to guessing - 50/50 chance.
By choosing 1 white hat out of 30, Tom gives Ray a test sample that makes the solution seem simple…