You find yourself in a closed room with 6 strangers. A guard comes in and says that some time later you are all going to be moved into separate cells and you won’t be able to communicate with one another. Then each of you will be assigned 1 of the 7 colors of the rainbow (red, orange, yellow, green, blue, indigo, violet). However, each of you will be told only the colors of the other 6 prisoners in random order.
If at least one of you guesses their color correctly, then all of you will be freed. However, if none of you guesses correctly, each of you will be tossed in a dark cell and you will not see rainbow ever again. Each of you is given only one chance to guess the color.
After the guard leaves the room, discussion starts:
- The 1st person suggests to overpower the guard when they come back.
- The 2nd person points out there may be more guards and closed doors outside. Also, one or more of you might get hurt in the process.
- The 3rd person proposes that everyone should just say a different color. Upon reflection, he decides that it’s better if everyone says the same color.
- The 4th person criticizes the 3rd person idea: the colors are probably not uniquely assigned otherwise it would be easy to tell what color you have after hearing the other 6.
- The 5th person mumbles something about a spy who will always work against any strategy you’ll come up with.
- The 6th person thinks that you should trust each other or at least assume that everyone will work with the strategy or you will never escape.
Everyone now waits for your opinion on the matter. Is there a strategy (without breaking the rules of the game) which can guarantee you freedom? If yes, present the strategy and prove that it works. If not, show the best possible strategy (in terms of probability of winning) and that there doesn’t exist a better one.
Hint 1: There exists a perfect strategy.
Hint 2: Replace colors with unique integers in range to (for example , , and so on).
You agree to assign each color a unique number from to , for example orange is assigned number and violet is assigned number . Each person is also assigned a single unique number from the same range, for example you could get number .
Now, when you get information about other colors, sum their assigned numbers together. For example, set gives sum . Add to the sum the smallest number which makes the result divided by your unique number. In the example, gives remainder of when divided by 7, so you must add in order to get a remainder of , your unique number. The number you needed to add represents the color you must tell the guard.
With this strategy, no matter what colors are assigned, exactly one of you will answer correctly and you will all be freed.
You probably don’t believe the above claim that the described strategy works so I shall provide proof which will give insight on why the strategy works.
In fact, we can even generalize the strategy. Let’s assume the number of prisoners is and that the number of colors is not greater than (we’ll see why this assumption is necessary later). We assign each prisoner and color a number in range .
Let be colors assigned to prisoners so that is an integer representing a color assigned to th prisoner. The sum of them is then .
Let’s define a sequence for each in range. It represents the knowledge of each prisoner: the sum of all colors except his own.
Each prisoner then solves exactly one of the following equations for :
From the definition of we know that in each of the equations, so th prisoner solves an equation equivalent to .
Since is in range exactly one of the equations is true.
Since is not greater than , it is a unique solution for each of the equations. To see why the assumption about the number of colors is necessary, suppose the number of colors was greater than . Then by pigeonhole principle there are at least different possible colors which will be solutions to at least one of the equations (since they give the same reminder when divided by ). This means that at least one prisoner has to guess from more than one possible colors and the probability of winning is less than .
The puzzle is not mine, I stumbled upon the puzzle while browsing Quora.