text: puzzle: how can you save the 100 prisoners from execution? the warden of a jail goes to the 100 prisoners in the jail and tells them he has a problem with overcrowding.   he devises the following test where he will put a hat, either white or black, on the head of each of prisoner.  there will be at least one hat of each color, but beyond that there is no limit to the number of hats of each color.  the prisoners can see everyone else's hat, but their own.  after the test commences, they will not be able to signal or otherwise communicate other than to say 'white' or 'black'.  he also says that the test will be all pass or all fail.  so everyone must state their hat correctly, but if any one person states incorrectly, all 100 prisoners will be executed.  the prisoners are given 20 minutes to discuss the situation and then will have the hats placed on their heads.  so they go and discuss for some time. and after they come back, the warden starts the test. interestingly, each of them answers correctly and hence all are released. how? we can arrive at this by considering some of the simpler cases.  let's assume that the warden placed only 1 white hat on my head and 99 black hats on everyone else's head.  so at the time when the warden said start, i would look around and see 99 black hats.  since there has to be at least one 1 hat, i would immediately announce that i had a white hat.  everyone else would then know that they had black hats and would say so.  now consider the case where i have a white hat and someone else also has a white hat.  i would look and see 1 white hat.  if i had a black hat, that person would immediately announce that they had a white hat.  but that doesn't happen.  instead they wait.  now since neither of us was able to announce right away, we know that there must be 2 white hats.  so we both announce that we have white hats.  you can follow this pattern with 3 white hats, etc. but it requires that you have a plan in place for timing.  let's say that everyone will wait ten seconds for every hat they see less of.  so if i see no white hats, i will immediately announce "white" after 0 seconds.  everyone else will follow with "black" right after.  similarly, if i saw 1 white hat, i would plan to say white after 10 seconds.  if no one announced after 0 seconds, i would be correct.  then everyone else would say "black" after that.  it doesn't matter the number of hats or whether there are more or less of one color as long as we wait a discrete period of time to announce.  i chose periods of 10 seconds so that there wouldn't be a chance of mistakes.  if there are w white hats and b black hats, then: everyone wearing a white hat will see w-1 white hats and b black hats. everyone wearing a black hat will see b-1 black hats and w white hats.  there are 3 cases: if w < b then all white hats will say 'white' at the same time (10(w-1) seconds), and everyone else knows they are wearing black.  if b < w then all black hats will say 'black' at the same time (10(b-1) seconds), and everyone else knows they are wearing white.  if w = b then all prisoners will know their color at the same time. (10(b-1) seconds, or 10(w-1) seconds, they are equivalent).   let's take an example.  if there were 51 white hats and 49 black hats, and i was wearing a white hat.  then i would plan to say "black" after 490 seconds.  however, the people in black hats would beat me to the punch saying "black" after 480 seconds.  then i would say "white" along with all the rest of the prisoners wearing white hats.  the "hat puzzle" is described in detail at wikipedia and i've included the link below.  i think the first answerer quoted from there but didn't include the reference.