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. Everyday 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 already have been in the living room. If this assertion is false, all 100 prisoners are executed. If it is correct, all prisoners are 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 they will be set free?
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 199 times, this will mean that all followers have already visited the room. Then he can make the assertion and set everyone free.