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?