There are 2015 people standing in a line. Each person is given one hat to wear. A hat has one of 2015 possible colors, and it is possible to distinguish from these 2015 colors. Duplicate hat colors are possible.
A person cannot see his own hat color or the hats of the people behind him, but he can see the colors of the hats of all the people in front of him. (Note that the person at the back of the line can see everyone else's hats and the person in front can see no one's hats.)
Starting from the back of the line and moving to the front, each person is asked to guess the color of their own hat. If a person guesses his or her hat color correctly, the person gets to keep the hat. If not, he or she has to give up the hat.
The 2015 people are allowed to devise a strategy before they form the line. They agree on a strategy that maximizes the number of hats guaranteed to be kept. What is ?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
You may have seen an easier problem with only two or three hat colors possible. Nevertheless, the strategy here is still the same. First, the people set each hat color to a distinct residue ( m o d 2 0 1 5 ) i.e. color 1 is 0 ( m o d 2 0 1 5 ) , color 2 is 1 ( m o d 2 0 1 5 ) , and so forth.
When the person in the back is asked to guess her own hat color, instead she adds up the values of the colors of all the hats in front of her and says the hat color that corresponds with her result. For example, if the first person had a hat with color 5 and the rest had hats with color 2, she would calculate 2 0 1 3 ( 1 ) + 4 ( m o d 2 0 1 5 ) , which is 2 ( m o d 2 0 1 5 ) . The hat color corresponding to 2 ( m o d 2 0 1 5 ) is color 3, so she would say that color, whatever it is. It is not guaranteed that she will guess her own hat color correctly, though.
Continuing with our example, the person that is second to last hears the last person say "color 3" and immediately knows that the sum of the 2 0 1 3 hat in front of him plus his own is congruent to 2 ( m o d 2 0 1 5 ) . He sees 2 0 1 2 hats of color 2 and 1 hat of color 5, so he calculates the sum of the hats in front of him as 2 0 1 2 ( 1 ) + 4 ≡ 1 ( m o d 2 0 1 5 ) . Then, he would know that the color of the hat on his head was congruent to 2 − 1 ≡ 1 ( m o d 2 0 1 5 ) , which corresponds to color 2. So, he says that color out loud, and he would get to keep his hat.
This continues up to the first person in line. Therefore, at a minimum, the first 2014 people get to keep their hats and the last person does not, so the answer is 2 0 1 4 .