There are 100 prisoners in solitary cells. There is a central living room with one light bulb in it, which can be either on or off initially. No prisoner can see the light bulb from his or her own cell. Every day, the warden picks a prisoner at random and that prisoner visits the living room. While there, the prisoner can toggle the light bulb if he wishes to do so. Also, at any time, every prisoner has the option of asserting that all 100 prisoners have already been in the living room. If this assertion is false, all 100 prisoners will be executed. If it is correct, all prisoners will be set free.
The prisoners are allowed to get together one night in the courtyard and come up with a plan. What plan should they agree on, so that eventually someone will make a correct assertion and will set everyone free, assuming the warden will bring each of them an infinite number of times to the central living room?
First, the prisoners should elect one of them to be a leader and the rest – followers. The first two times a follower visits the living room and sees that the light bulb is turned off, he should turn it on; after that he shouldn’t touch it anymore. Every time the leader visits the living room and sees that the light bulb is turned on, he should turn it off. After the leader turns off the lightbulb 198 times, this will mean that all followers have already visited the room. Then he can make the assertion and set everyone free.