# 100 Prisoners and a Light Bulb

Do you want a real challenging mathematical brain teaser? Help these 100 prisoners escape.

100 prisoners are imprisoned in solitary cells. Each cell is windowless and soundproof. There’s a central living room with one light bulb; the bulb is initially off. No prisoner can see the light bulb from his or her own cell. Each day, the warden picks a prisoner equally at random, and that prisoner visits the central living room; at the end of the day the prisoner is returned to his cell. While in the living room, the prisoner can toggle the bulb if he or she wishes. Also, the prisoner has the option of asserting the claim that all 100 prisoners have been to the living room. If this assertion is false (that is, some prisoners still haven’t been to the living room), all 100 prisoners will be shot for their stupidity. However, if it is indeed true, all prisoners are set free and inducted into MENSA, since the world can always use more smart people. Thus, the assertion should only be made if the prisoner is 100% certain of its validity.

Before this whole procedure begins, the prisoners are allowed to get together in the courtyard to discuss a plan. What is the optimal plan they can agree on, so that eventually, someone will make a correct assertion?

Note 1: What is meant by optimal? If your solution is optimal, it means you can prove that no other algorithm can produce a lower average running time. This is usually very hard to do though. So the best we can do in the meantime is try to beat the best average running time we know of. The number to beat so far is around 3500 days. If you get a number around 27-28 years, then you’ve found the solution most people who solve the puzzle come up with. However, it’s not optimal.

Note 2: How to compute average running time? The preferred method is to do a probabilistic analysis using pencil and paper. But if you haven’t learned about stuff like that, a much simpler way is to just program your solution and run it maybe 100 times, recording how many days elapsed in each invocation. Afterwards you should have an array of 100 numbers. Now take the average of all them, and you’ll have an empirical average which is close to the theoretical one.

Source