﻿

# Prisoners and hats puzzle

The prisoners and hats puzzle is an induction puzzle (a kind of logic puzzle) that involves reasoning about the actions of other people, drawing in aspects of Game theory. There are many variations, but the central theme remains the same. Not to be confused with the similar Hat Puzzle.

The puzzle

According to the story, four prisoners are arrested for a crime, but the jail is full and the jailer has nowhere to put them. He eventually comes up with the solution of giving them a puzzle so if they succeed they can go free but if they fail they are executed.

The jailer puts three of the men sitting in a line. The fourth man is put behind a screen (or in a separate room). He gives all four men party hats (as in diagram). The jailer explains that there are two red and two blue hats. The prisoners can see the hats in front of them but not on themselves or behind. The fourth man behind the screen can't see or be seen by any other prisoner. No communication between the men is allowed.

If any prisoner can figure out and say (out loud) to the jailer what colour hat he has on his head "all four prisoners go free". The puzzle is to find how the prisoners can escape.

The solution

For the sake of explanation let's label the prisoners in line order A B and C. Thus B can see A (and his hat colour) and C can see A and B.

The prisoners know that there are only two hats of each colour. So if C observes that A and B have hats of the same colour, C would deduce that his own hat is the opposite colour. However, if A and B have hats of different colours, then C can say nothing. The key is that prisoner B, after allowing an appropriate interval, and knowing what C would do, can deduce that if C says nothing the hats on A and B must be different. Being able to see A's hat he can deduce his own hat colour. (The fourth prisoner is irrelevant to the puzzle: his only purpose is to wear the fourth hat).

In common with many puzzles of this type, the solution relies on the assumption that all participants are totally rational and are intelligent enough to make the appropriate deductions.

After solving this puzzle, some insight into the nature of communication can be gained by pondering whether the meaningful silence of prisoner C violates the "No communication" rule (given that communication is usually defined as the "transfer of information").

Variant

In a variant of this puzzle there are 3 hats of one colour and only 1 hat of another, and the 3 prisoners can see each other i.e. A sees B & C, B sees A & C and C sees A & B. (D again not to be seen and only there to wear the last hat)

The solution

There are two possible ways to solve this puzzle: the trivial way would be that one of the 3 prisoners wears the single off-colour hat, and thus the other two can easily deduce the colour of theirs.In the non trivial case each prisoner wears a hat of the same colour (while D wears the off colour hat).After a while the one of the prisoners should be able to deduce that, since none of the other was able to state the colour of his own hat, he must wear a hat of the same colour as the others.

Three-Hat Variant

In this variant there are 3 prisoners and 3 hats. Each prisoner is assigned a random hat, either red or blue. Each person can see the hats of two others, but not their own. On a clue, they each have to guess their own hat color or pass. They win release if at least one person guessed correctly and none guessed incorrectly (passing is neither correct nor incorrect).

This puzzle doesn't have a 100% winning strategy, so the question is: What is the best strategy? Which strategy has the highest probability of winning?

If you think of colors of hats as bits, this problem has some important applications in coding theory.

The solution and the discussion of this puzzle can be found [http://www.relisoft.com/science/hats.html here] (also a solution to the analogous 7-hat puzzle) and other 3 variants are available on this [http://brainden.com/logic-puzzles.htm Logic Puzzles] page (they are called Masters of Logic I-IV).

Ten-Hat Variant

In this variant there are 10 prisoners and 10 hats. Each prisoner is assigned a random hat, either red or blue, but the number of each color hat is not known to the prisoners. The prisoners will be lined up single file where each can see the hats in front of him but not behind. Starting with the prisoner in the back of the line and moving forward, they must each, in turn, say only one word which must be "red" or "blue". If the word matches their hat color they are released, if not, they are killed on the spot. A friendly guard warns them of this test one hour beforehand and tells them that they can formulate a plan where by following the stated rules, 9 of the 10 prisoners will definitely survive, and 1 has a 50/50 chance of survival. What is the plan to achieve the goal?

Ten-Hat Solution

The prisoners can use a binary code where each blue hat = 0 and each red hat = 1. The prisoner in the back of the line adds up all the values and if the sum is even he says "blue" (blue being =0 and therefore even) and if the sum is odd he says "red". This prisoner has a 50/50 chance of having the hat color that he said, but each subsequent prisoner can calculate his own color by adding up the hats in front (and behind after hearing the answers [excluding the prisoner in the back] ) and comparing it to the initial answer given by the prisoner in the back of the line. The total number of red hats has to be an even or odd number matching the initial even or odd answer given by the prisoner in back.

Countably Infinite-Hat Variant

In this variant, a countably infinite number of prisoners, each with an unknown and randomly assigned red or blue hat line up single file line. Each prisoner faces away from the beginning of the line, and each prisoner can see all the hats in front of him, and none of the hats behind. Starting from the beginning of the line, each prisoner must correctly identify the color of his hat or he is killed on the spot. As before, the prisoners have a chance to meet beforehand, but unlike before, once in line, no prisoner can hear what the other prisoners say. The question is, is there a way to ensure that only finitely many prisoners are killed (and hence, an infinite number are saved)?

Countably Infinite-Hat Solution

If one accepts the axiom of choice, the answer is yes. In fact, even if we allow an uncountable number of different colors for the hats, the axiom of choice provides a solution that guarantees that only finitely many prisoners must die. The solution for the two color case is as follows, and the solution for the uncountably infinite color case is essentially the same:

The prisoners standing in line form a sequence of 0's and 1's, where 0 is taken to represent blue, and 1 is taken to represent red. Before they are put into the line, the prisoners define the following equivalence relation over all possible sequences that they might be put into: Two sequences are equivalent if they are identical after a finite number of entries. From this equivalence relation, the prisoners get a collection of equivalence classes. Using the axiom of choice, they select and memorize a representative sequence from each equivalence class.

When they are put into their line, each prisoner can see what equivalence class the "actual" sequence of hats belongs to. They then proceed guessing their hat color as if they were in the "representative" sequence from the appropriate equivalence class. Since the actual sequence and the representative sequence are in the same equivalence class, their entries are the same after finitely many prisoners. The prisoners up to this finite point have a 1/2 chance of being killed. All prisoners after this point will be saved.

Infinite-Hat variation

The number of hats (prisoners) can be infinite provided a prior code is madeby the prisoners using the same allowed word. (The rules state: one word, taken as using the same word, and not being taken as using a single word.) That is, the same one (correct) word may be repeated more than once. With this prior collusion the prisoners can go free.E.g. if there were 20 prisoners inline with 20 various blue and red hats. The 20th, last in line, without any considered or prior information, would be at risk. However, by calling the hat colour of the 19th prisoner (in front of him) he has a 50/50 chance of going free; and guarantees the 19th prisoner can go free.

The 19th now calls (correctly) his own hat colour (as informed by number 20) and; if prisoner 18 (in front of number 19) has the same colour hat, the correct colour 19 calls will also confirmed the same colour to prisoner 18.

However, if prisoner 18 has the other colour hat, prisoner 19 repeats his own correct hat colour twice. As previously agreed between the prisoners, this repeat, of the same correct colour word, informs prisoner 18 that his hat colour is actually the opposite colour to that called by prisoner 19. Simply: the repeat of the same, correct colour word informs the next prisoner in line that his hat is of the other colour. That is, a repeat (of the correct colour) toggles that colour, for the prisoner in front. i.e. red=red. red,red,=blue.

This toggle can be used by all the prisoners each in turn, who will both correctly call their own colour every time; either once or twice, and so doing, will also directly inform the prisoner in front of the colour they have to correctly call. Enabling in this instance, at least 19 prisoners to go free, and possibly all 20.

If using the one (correct) word more thanonce is not allowed, the solution can be varied by different use of the toggle for one word. Just the one word could be said, e.g. either loudly or softly. i.e. If the hat in front is the same colour, the correct colour is called softly; and, if the hat in front is of the other colour, the correct colour could called loudly.

ee also

* Hat Puzzle

The above problem can also be solved in the following waySuppose there are 20 prisoners. Now prisoner no. 20 is at risk due to lack of prior information. He calls a color according to the devised strategy. He calls the color which is in even number i.e he counts all red/blue caps in front of him now he calls red if red is even or calls blue if blue is even. he has a 50:50 chance of survival. Now if he calls red the 19th person knows that there are even no. of red hats so he too counts the red hats if he finds odd no. of red hats that means that his hat is red he calls red. the 18th person also knows that the total no. of red hats is even and there was one red hat behind him (excluding the 20th person) so if he finds odd no. of red hats in front of him then his hat cannot be red as adding 1 red hat (of the 19th person) it becomes even and if his was red the count should have been even in front of him. hence rest of the people are saved in the similar manner

Wikimedia Foundation. 2010.

### Look at other dictionaries:

• Hat puzzle — The hat puzzle is a classic logic problem, attributed to Todd Ebert, in his 1998 Ph.D. thesis at the University of California, Santa Barbara. It is a strategy question about a cooperative game, which has been shown to have connections to… …   Wikipedia

• List of puzzle topics — This is a list of puzzle topics, by Wikipedia page.See also: * List of impossible puzzles * List of puzzle based computer and video games * List of game topics.* Acrostic * Anagram * Back from the klondike * Burr puzzle * Chess problem * Chess… …   Wikipedia

• List of Doctor Who universe creatures and aliens — This is a list of fictional creatures and aliens from the universe of the long running BBC science fiction television series Doctor Who, including Torchwood, The Sarah Jane Adventures and K 9. It covers alien races and other fictional creatures,… …   Wikipedia

• Induction puzzles — are Logic puzzles which are solved via the application of the principle of induction. In most cases, the puzzle s scenario will involve several participants with reasoning capability (typically people) and the solution to the puzzle will be based …   Wikipedia

• Рефлексия — У этого термина существуют и другие значения, см. Рефлексия (значения). Эта статья или раздел нуждается в переработке. Пожалуйста, улучшите статью в соответствии …   Википедия

• List of One Piece episodes (season 9) — The cover of the first DVD compilation released by Toei Animation of the ninth season The ninth season of the One Piece anime series was directed by Kōnosuke Uda and produced by Toei Animation. Like the rest of the series, it follows the… …   Wikipedia

• Europe, history of — Introduction       history of European peoples and cultures from prehistoric times to the present. Europe is a more ambiguous term than most geographic expressions. Its etymology is doubtful, as is the physical extent of the area it designates.… …   Universalium

• literature — /lit euhr euh cheuhr, choor , li treuh /, n. 1. writings in which expression and form, in connection with ideas of permanent and universal interest, are characteristic or essential features, as poetry, novels, history, biography, and essays. 2.… …   Universalium

• performing arts — arts or skills that require public performance, as acting, singing, or dancing. [1945 50] * * * ▪ 2009 Introduction Music Classical.       The last vestiges of the Cold War seemed to thaw for a moment on Feb. 26, 2008, when the unfamiliar strains …   Universalium

• List of Celebrity Deathmatch episodes — This is the list of all the episodes and fights in the claymation series Celebrity Deathmatch. Bolded characters s names are the winners in a fight. Contents 1 Pilot episodes (January 1 25, 1998) …   Wikipedia