Some people are on an island…
One morning, they wake up to discover that some of them have had magical hats stuck on their heads the night before. It is impossible for someone to directly sense if they have a hat on their own head, but the hats on other people’s heads are all visible to each person. Also, everyone can shut their eyes and sense if anyone is still wearing a hat. Pretty crazy, but like I said – magical hats.
The hats can only be removed by going for a swim at midnight, and the people all want to remove the hats as soon as possible. However, going for a swim if you aren’t wearing a hat is really really unpleasant and nobody trusts anybody else.
How many nights before all the hats have been removed?
Supplementary problem: How many nights before all the hats are removed if the people trust each other?