math.dartmouth.edupw/math7/margolese6.docx · web viewrachel margolese. math 7. may 23, 2013....
TRANSCRIPT
Margolese 1
Rachel MargoleseMath 7May 23, 2013
Hats on Hats
Gentlemen in hats. Prisoners in hats. Dwarves in hats. White hats. Black hats. Red hats.
Blue hats. Every hat on every head proposes a new puzzle and a new way to consider puzzles.
Just as the characters in the multitude of hat puzzles all have a different perspective of all of the
hats and what different people are wearing, each puzzler who encounters a hat puzzle will have a
slightly different insight into the puzzle. For the seasoned mathematician, hat puzzles have
provided a gateway into the study of the mathematical branch of coding theory—an absolutely
fascinating discipline for some but for the layperson perhaps not the most engaging topic. What
is exciting however is a convoluted story of a group of prisoners forced to wear strange hats and
who can only escape from their dire situation if you, the puzzler, can use your wits and clever
deduction to set them free. These are two ways in which to consider a hat puzzle, as a captivating
story and diverting game of wit, or as an intriguing analogue to coding theory giving way to new
insights in the discipline of mathematics. Hat puzzles accomplish this duel purpose through their
intrinsic property of being easily expanded or varied. In practice, any slight variation of a hat
puzzle—either varying the number of hats or changing the information that each character has
access to—produces a remarkably distinctive puzzle with an equally distinctive solution. This is,
perhaps, not unique to hat puzzles in particular but it is particularly striking within the hat puzzle
genre.
The puzzle precursor to the modern hat puzzle genre appeared in a puzzle book by
George Gamov and Marvin Stern in 1958 and depicted three commuters with sooty faces.i
During the following decades, the puzzle was re-imagined into the three hat puzzle that appeared
Margolese 2
in Todd Ebert’s 1998 Ph.D dissertation and became the classic hat puzzle that puzzlers use
today.ii The puzzle begins simply with three prisoners. As each prisoner enters a room, a coin is
flipped, with the outcome determining what color hat that prisoner will wear: white if heads,
brown if tails. Once all three prisoners are wearing their hats, each prisoner will be taken aside
and given an opportunity to guess the color of her own hat, at which point she may either guess a
color or pass. The deal is that, if all of the prisoners who decide to venture a guess, guess
correctly, all of the prisoners will be set free. If none of the prisoners guess, or if any prisoner
guesses incorrectly, then all of the prisoners will be sentenced immediately to death row. The
prisoners are given time to strategize before they are given their hats, but once they are wearing
their hats, they may have no further communication with one another, nor can they see their own
hat. What strategy gives the prisoners the best odds of survival?
The immediate solution that many people come up with is to decide to have one prisoner
guess and one prisoner only. Since the combination of colored hats is chosen completely at
random, she’ll have exactly a 50% chance of guessing correctly. But let’s see if we can get better
odds than that. Consider the situation from the viewpoint of each prisoner, starting with prisoner
A. There are three distinct possibilities of combinations of hats that she might see, which are
outlined in Table 1. As the color of the hats that she sees have no baring on the color of her own
hat, this information is insufficient for the prisoner to make an educated guess with regards to her
personal hat. Thus, we must conclude that there is no solution which can guarantee her safety
and, as such, we are only searching for a solution which gives the highest possible chance of
survival. Now, move from the single prisoner’s viewpoint to the omniscient viewpoint. From
here, we see that there are eight possibilities of combinations of hats, outlined in Table 2. From a
probabilistic overview of these combinations, we see that, out of the eight combinations, there
Margolese 3
are only two in which all three hats are the same color. Phrased another way, we see that six of
the eight hat combinations consist of two hats of the same color and one hat of the opposite
color. Thus, if you are a prisoner and you see two hats of the same color, chances are six out of
eight (or 75%) that you are wearing the opposite color hat to those that you see. On the other
hand, if you see two hats of opposite colors, your hat is, with equal probability, either one of
those colors, and thus you have no way of increasing your chances of a correct guess to above
50%.
This analysis leads us to a possible solution to maximize the chance of survival. Since
you have a 75% chance of correctly guessing your hat color if you see two hats of the same
color, you should guess your hat color in these cases. If you see two hats of opposite colors, you
should pass your guess because you only have a 50% chance of guessing correctly. As we can
see from Table 2, this strategy will give the prisoners a 75% chance of survival. To the
layperson, this is a clever and satisfying solution, puzzle complete. But the curious few may
wonder how does that work? How can a person have a greater than 50% of guessing a randomly
chosen color using information that has no effect on her chosen color? Phrased that way, yes, the
solution appears to be a strange anomaly, a trick of logic. However, that ‘trick of logic’ is
grounded in coding theory and has spawned exploration into an area of coding theory known as
error-correcting codes.
Before getting into the mathematical theory, let’s examine three alternative variations of
the original three-hat puzzle. The first puzzle brings us to four men captured by Nazis. The Nazi
general wants to have a little fun with these prisoners and so he engages them in a wager of wits
with their freedom as the prize. The general takes three of the soldiers into one room and
immobilizes each man in a chair, one behind the other. Soldier A can see soldiers B and C,
Margolese 4
soldier B can see soldier C, and soldier C can only see the wall in front of him. The general then
brings soldier D to another room where the soldier can only see the four cement walls
surrounding him. The general then shows the soldiers four hats: two white hats and two black
hats and tells the soldiers that he will put one hat on each soldier. If any one of the four soldiers
can guess the color of his hat without communicating or in any way signaling to the others, all
four men will be set free. The general then blindfolds the soldiers, places a hat on each soldier’s
head, and takes the blindfolds off. Will the soldiers earn their freedom? If so, who will set them
free?
As the omniscient puzzle solver, you have the power to set up the puzzle as you see fit;
you decide which soldier has on which hat with each hat placement depending on the locations
of all the other hats’ placements. Knowing all of the hat locations doesn’t help you understand
how each soldier will guess. Thus, in order to solve the puzzle, you must disregard part of the
information that you know as the omniscient puzzle solver and put yourself into the puzzle and
into the place of each soldier one-by-one. Start with the isolated soldier. Obviously, he has no
information about any of the hats, so he has no chance of definitively guessing his hat correctly.
Next, sit in the seat of soldier A, who can see the two men and their hats in front of him. From
this vantage point, there are three different views you can have: two white hats, two black hats,
or a white and a black hat. If you see two hats of the same color, you know you must have the
other color hat because there are only two hats of each color. Therefore, only in these two cases,
soldier A will set the group free. But, in the situation where you see one of each color, you could
be wearing either a black or a white hat; there is not enough information for you to know what
color hat you are wearing. Now, sit in soldier B’s seat. From here, you can see only the hat in
front of you, which is either black or white. In this seat, however, you have more information
Margolese 5
than just what you see. If the soldier behind you saw two black hats or two white hats, he would
immediately say the opposite color that he saw. However, in the case where the soldier behind
you says nothing, you know that he must see one of each hat color. His silence tells you that you
must be wearing the opposite color of the hat that you see in front of you.
Just as in all other hat puzzles, the solution to this four-hat variation lies not through
information supplied to the omniscient viewer, but through the eyes of the characters in the
puzzle. In this analysis, we can begin to see the foundation of the error correcting code theory
imbedded in the solution to the problem. In computer science, error-correcting codes are codes
which are essentially able to check a string of bits and detect any single error that is contained
within that string—an error being a flipped bit, either a 0 has become a 1, or a 1 has become a
zero. For these codes to work, there must be some factor which is dependent on the status of each
of the bits and would thus change if any of the bits were to change. The four-hat puzzle offers a
very basic view of how error codes work; in this puzzle, each element within the puzzle can look
around, add up what he sees, and deduce whether he has enough information to decide the status
of his own color. In much the same way, error-correcting codes use the status’ of the
information-containing bits to determine the status of a checking bit, that checking bit being
analogous to a soldier who is looking at the other hats. In both the code and the puzzle there is a
constraint which is integral for the checking to occur—in the puzzle it’s the fact that of the four
hats, two are white and two are black, and in the code it’s the fact that the checking bit holds
information which relates to the orientation of all of the other bits.
The four hat puzzle gives us a rudimentary look at how error-correcting code relates to
hat puzzles. Now let’s consider a hat puzzle which involves a greater internal dependence from
one hat to the next. For entertainment, a sadistic wizard captures ten dwarves. He proposes a
Margolese 6
deal. The ten dwarves will line up in a straight line, and each will be wearing either a blue or an
orange hat. They could all be wearing blue hats or all orange hats, or any combination of blue
and orange hats. The dwarf in the back will be able to see all nine of dwarves in front of him, the
second to last dwarf will be able to see all eight dwarves in front of him, and so on down the line
until the first dwarf in line who will not be able to see any dwarves. The deal the wizard proposes
is this: each dwarf will guess the color of his own hat (which he cannot see), starting with the
dwarf in the back of the line, who can see all nine dwarves in front of him. If he guesses right,
that dwarf is set free. If he guesses incorrectly, he is immediately, and silently, killed. The wizard
allows the dwarfs to conceive a plan before they are lined up. All of the dwarves hear each guess
that is made, but they do not know if the dwarf who is guessing is killed or not. They are not
allowed to turn around once they are in line, so each dwarf can only see the hats on the dwarves
in front of him. Additionally, they are not allowed to communicate in any way once they are
lined up. However, all dwarves do hear the single hat guess that each dwarf makes. How many
dwarves can be saved and how?
As before, let us first try to insert ourselves into the puzzle. Start by imagining yourself as
the last dwarf in line, the dwarf who can see all nine dwarves in front of him. From this position,
you can see nine hats, some of which are blue and some of which are orange. Seeing these nine
hats gives you no information pertaining to your own hat. So you must guess randomly. Now put
yourself in the place of the ninth dwarf in line, the one who can see eight dwarves in front of
him. You just heard the dwarf behind you guess a color, say blue. You also see the eight colors
in front of you. In total, you have eight hats to look at, some blue, some orange, and one guess
from behind. Without any preconceived plan, this information tells you nothing about your own
hat and is insufficient information to produce a reasonable guess about your hat. You need more
Margolese 7
information. The only way you can glean more information while in line is through the guesses
that each dwarf behind you makes. Now consider possible plans that you could have come up
with before getting into line which could be used to pass along additional information about hats.
Consider a simple plan where every other dwarf says the color of the hat in front of him. In this
manner, every other dwarf would know the color of his own hat and be safe, while the other five
dwarves only have a 50% chance of being saved. Of course, assuming that this is an evil wizard,
he could arrange it so that the hats alternate colors such that the sacrificial dwarves will all be
killed. Thus, this plan can save 5 dwarves. Is there a better stragety?
Through their planning, the dwarves must come up with a scheme by which to convey
information about all of the hats in front of them, as we have seen that only conveying
information about a single hat in front of you cannot save a majority of the dwarves. Considering
the possible characteristics of the hats in front of you, one characteristic is the number of each
color and more specifically the oddness or evenness of that number. Say you are the second
dwarf in line; you might see five orange hats and three blue hats. How can you convey, in one
word, the number of each hat color that you see? You only need to convey information about one
of the colors, because if you know how many orange hats there are, you can then easily deduce
the number of blue hats. As we saw in the beginning, the dwarf in back has no information
besides the nine hats he sees and he cannot access any additional information before he makes
his guess. From this, we can see that there is no way to guarantee his survival. But his death need
not be in vain. He sees in front of him all of the dwarves’ hats, say six orange hats and three blue
hats. Let’s focus on just the orange hats. One characteristic of the number of orange hats is
whether there is an odd or even number. So, since the last dwarf in line cannot guarantee his own
safety, he can guess a color that will tell the rest of the dwarves whether he sees an odd number
Margolese 8
of orange hats or an even number of hats. Say he conveys that he sees an even number of orange
hats. Then, imagine yourself as the ninth dwarf in line. You look ahead and see five orange hats,
which is an odd number. Ergo, since the dwarf behind you saw an even number of hats, you must
be wearing an orange hat. You announce your guess of orange. Then, the eight dwarf in line
looks ahead and sees five orange hats. Since the first dwarf said there were an even number of
orange hats, and the second dwarf guessed orange, that second dwarf must have seen an odd
number of hats. Therefore, if this third dwarf to guess also sees an odd number of orange hats, he
must be wearing a blue hat. Using this logic, the dwarves continue down the line and all of them
are set free—except for the unfortunate dwarf in the back of the line, may he rest in peace.
The only detail left is to figure out how that first dwarf conveys the oddness or evenness
of the number of orange hats. Since the dwarves have time to plan before they line up, they could
decide that the first dwarf should guess orange if there are an even number of orange hats, and
blue if there are an odd number of orange hats. In this manner, 9 out of 10 dwarves can be saved,
which is an excellent survival rate.
At this point, we have reached an excellent and logical solution—even without
continuing into the coding theory, a puzzler could leave this puzzle content. While solving this
puzzle, we saw that the method of inserting yourself into the puzzle will only get you so far into
the solution. The leap from discovering that the dwarves need more information besides the hats
that they can see and deciding that the backmost dwarf must convey the oddness or evenness of
the number of orange hats requires some familiarity with working with numbers. Though a
difficult leap to make when solving this puzzle, the use of the oddness or evenness characteristic
of the number of orange hats is key to error-correcting codes in this example. Slightly different
from the previous example, with the dwarves, each hat guess depends on all of the previous
Margolese 9
guesses with the first guess being a pre-determined bit of information. All of the guesses depend
upon the first guess and in this way the first guess also contains information about all of the other
nine guesses, which is the crux of error-correcting codes.
Finally, lets consider one last variation on the original hat puzzle. In this version, given
one more piece of information, and a slight variation of rules, we can guarantee survival for all
prisoners. As in the first puzzle, there are three prisoners each wearing a randomly selected
colored hat, either brown or white. Once each prisoner is wearing a hat, the prison guard asks the
prisoners to raise their hands if they see a brown hat. All prisoners raise their hands. The
prisoners are then asked keep their hands up if they can guess their hat color. All hands go down.
The guard tells them that at least one prisoner must guess correctly for them to be set free. How
do the prisoners survive?
Once again, consider what prisoner A sees. She looks out and sees either one brown hat
and one white hat, or two brown hats. Let’s say she sees a white and a brown hat. Now she
considers what the prisoner wearing the brown hat must see. Since that prisoner raised her hand
to say that she had seen a brown hat, one of the two hats that she is looking at must be brown.
Therefore, since the third prisoner’s hat is white, prisoner A’s hat must be brown.
What if prisoner A looks out and sees two brown hats? Then she has no way of knowing
if her hat is brown or white, so she will remain silent. Now, move on to prisoner B, who looks
out and sees either a white and a brown hat or two brown hats. If she sees one of each color, she
will correctly guess her own hat using the same logic as we went through with A, but, if she sees
two brown hats, then she too will remain silent, hoping that someone else will have enough
information to deduce their hat color. Finally, prisoner C, hearing the silence of the first two
prisoners, can deduce that neither has seen two different colored hats because, if they had, they
Margolese 10
would have guessed their own hat color. Therefore, prisoner C can correctly deduce that she is
wearing a brown hat. Using this logic, the prisoners have a 100% chance of survival.
Much like in the four-prisoners variation, this puzzle requires logical interdependence
deduction where each prisoner must deduce what all of the other prisoners must be thinking in
order to make her own guess. Walking through this puzzle logically while considering the
situation from each of the prisoner’s viewpoint produces a very elegant pathway to find the
solution. In this solution, we can again see how the error-correcting codes are ingrained in the
dependence each prisoner has on the other two prisoners; each prisoner depends upon the logical
conclusions that the other two prisoners reach, i.e. that if prisoner A and prisoner B both remain
silent, they must both have deduced that they need prisoner C’s information in order to guess
their own hats. Thus, all color guesses are linked together and therefore interdependent.
Error-correcting codes, specifically Hamming codes which are a family of error-
correcting codes, make all of these hat problems very interesting for mathematicians. These last
three puzzles lay out different aspects of the error-correcting codes which helps to understand
just what is meant by an error-correcting code and how they relate to puzzles, but the original hat
puzzle is the real link to understanding the fascination mathematicians have with hat puzzles and
error codes. The three-hat original puzzle can be expanded to include seven, sixteen, even
hundreds of hats and by using coding theory, mathematicians have proven that the prisoners have
a better than 50% chance of survival. (To see the math behind error codes for large numbers of
prisoners read "The Hat Problem and Hamming Codes" in Focus (2001))iii This ability to expand
the puzzle to infinite many prisoners is what is so captivating for mathematicians looking to
expand modern mathematics, yet at the same time the puzzles have no need to be expanded to
provide entertainment and an excellent exercise in logical problem solving for other puzzle
Margolese 11
solvers. Hat puzzle have reached such a wide audience by both appealing to the mathematically
inclined crowd and to the recreational puzzler looking for a diversion. As each hat puzzle
revolves around the fact that the puzzle is solved through the eyes of the wearer and not the
beholder, hat puzzles are also unique from other puzzles; in these puzzles you get to be a part of
the puzzle and become a part of the puzzle story which is fun in its own right. Be a part of the
problem to find the solution.
Prisoner B Prisoner C
Brown Brown
Brown White
White White
Table 1: Possible combinations of hats which prisoner A could see.
Actually wearing Guess Survived?
Prisoner A Prisoner B Prisoner C Prisoner A Prisoner B Prisoner C
White White White Brown Brown Brown N
White White Brown -- -- Brown Y
Brown White White Brown -- -- Y
White Brown White -- Brown -- Y
Brown Brown Brown White White White N
Brown Brown White -- -- White Y
White Brown Brown White -- -- Y
Brown White Brown -- White -- Y
Margolese 12
Table 2: Possible combinations of hats that each prisoner could be wearing and each prisoner’s guess given the condition that they only guess if they see two of the same hat color.
Margolese 13
References
1. Bernstein, Mira. "The Hat Problem and Hamming Codes." Focus (2001): 4-6. Mathematical Association of America. Web. 21 May 2013
2. Guo, Wenge, Subramanyam Kasala, Bhaskara Rao, and Brian Tucker. The Hat Problem And Some Variations. Rep. N.p.: n.p., n.d. University of Cincinnati. Web. 15 May 2013. <http://web.njit.edu/~wguo/Hat%20Probelm.pdf>.
3. Hardin, Christopher S., and Alan D. Taylor. "An Introduction to Infinite Hat Problems." The Mathematical Intelligencer 30.4 (2008): 20-25. Spnnger Science + Business Medta, Inc. Web. 13 May 2013.
4. Robinson, Sara. "Why Mathematicians Now Care About Their Hat Color." The New York Times. The New York Times, 10 Apr. 2001. Web. 16 May 2013.
5. Stern, Marvin. "Three Soot Smeared Faces." Puzzle-math. By George Gamow. New York: Viking, 1958. 77-78. Print.
Endnotes
i Stern, Marvin. "Three Soot Smeared Faces." Puzzle-math. By George Gamow. New York: Viking, 1958. 77-78. Print.ii Hardin, Christopher S., and Alan D. Taylor. "An Introduction to Infinite Hat Problems." The Mathematical Intelligencer 30.4 (2008): 20-25. Spnnger Science + Business Medta, Inc. Web. 13 May 20 13.iii Bernstein, Mira. "The Hat Problem and Hamming Codes." Focus (2001): 4-6. Mathematical Association of America. Web. 21 May 2013.