A Hat Guessing Game

Problem: There are 100100 prisoners. A warden decides to play the following game:

Do the prisoners have a strategy to ensure they are all set free?

Thoughts: There are only 100100 options and 100100 prisoners so intuitively there should probably be a solution to this problem. Because if you imagined you had a multi choice question with 100100 options and you had 100100 different guesses then surely you would get the right answer eventually.

One of the first strategy we might think of then is to have every prisoner guesses a different number for their own hat. That is one prisoner guesses 11, another prisoner guesses 22 and so on. However this strategy doesn't work.

The reason this doesn't work is because each prisoner is not answering the same question. Each prisoner is answering a different question which is "What is the number on your own hat?". This is as if you had 100100 different multi choice questions and one attempt on each one. In such a situation it's possible that you get every question wrong.

So in order to solve this question we need to rephrase the question. Instead of each prisoner guessing their own hat number they need to be guessing some other quantity that is the same for all prisoners.

What if instead of guessing their own hat number they guessed the sum of all the hats of all the prisoners. If they could guess this correctly then the can determine their own hat number by subtracting the sum of all the other prisoners hats from the total sum. In fact it's enough to correctly guess the sum modulo 100100 because the value of their own hat is between 11 and 100100. Each possibility leads to a different value of the total sum mod 100100.

Solution: Each prisoner gets assigned a number 11 to 100100 before the game starts. Then each prisoner guesses the sum of all the hats modulo 100100 to be equal to their assigned number. This way exactly one prison will be correct.

Every prisoner then guesses their own hat number to be equal to their assigned number minus the sum of all the other prisoners hats modulo 100100. This way exactly one prisoner will correctly guess their own hat number.

Example: If there are two prisoners, two hats and the numbers are between 11 and 22 then either the two hats are either different or the same. This corresponds to the two possible sums modulo 22. Either the sum of the two hats is even or odd.

Prisoner 11 assumes the two hats are different. Prisoner 22 assumes the two hats are the same. One of them will be correct.