A group of explorers are captured by cannibals. (There are n explorers, where n is a positive integer) The cannibals are surprisingly hospitable, and take the explorers back to their village, where the explorers are fed and given shelter, but not allowed to leave. The cannibals tell the explorers that the following morning they will play a game, which will decide who will be eaten and who will be set free. The game works as follows:
The explorers will form a single-file line, and the cannibals will put a hat on each explorer. Each hat is either red or white, but no information is given about how many of each there are. Given the way they're lined up, each explorer can see all the hats on people in front of himself, but not his own hat or those of anyone behind him. In particular, the explorer at the front of the line can't see any hats, and the one at the back of the line can see all but his own. Starting from the back of the line, each explorer will say either "red" or "white". If his guess matches the color of his own hat, he is set free. If his guess doesn't match the color of his hat, he is killed and eaten.
The explorers have a night to plan their strategy. They decide that they would like to guarantee that at least some of them survive tomorrow's game, and hence genuine guessing is a bad strategy. On the other hand, they might devise a secret code without violating the rules of the game.
The riddle is this: what is the best strategy, and how many people can they guarantee will survive?