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?
P.S. Probabilistic analysis for this problem can be difficult, so try simulations to test out your solutions to see how long they take on average.
1) If the lightbulb is off, leave the room.
2) If the lightbulb is one, turn it off and increment his count.
Every other prisoner follows the following rules:
1) If the lightbulb is on, do not touch it.
2) If the lightbulb is off and you have not flipped it on before, flip it on.
3) If the lightbulb is off but you have previously flipped it on, then do not touch it.
When the counter reaches 100, he may tell the guard that everyone has visited.