Once in a prison with 100 prisoners, the Warden introduces a strange but interesting challenge to all the prisoners. This challenge can even grant them the freedom and thus every one of the prisoners becomes quite excited.
The warden selects one prisoner everyday randomly from the lot and moves him into a pitch black room with a bulb and a witch that controls the bulb. The prisoner can carry out three different actions in the room - He can switch on the bulb, switch it off or do nothing and sit idle. A prisoner can be picked up more than one time.
Now the warden introduces the twist in the challenge. He tells them that the prisoners can put a stop to the process any day they feel that every one of them has been confined to that room at least once. If the prisoners are correct, then every single one of them will be set free. But if they have put up a wrong judgment, all of them will be killed.
Seeking it to be the only chance of freedom, the prisoners take up the challenge. They are given some time to discuss regarding it before the process could begin. How will they plan things so that they are finally set free?
Solution:
They select one of the prisoner named Jason to do the trick and frame out a full proof plan. According to their plan, whenever a prisoner other than Jason is selected, they will follows some simple steps - If the bulb is off, they will switch it on but if the bulb is already lit, they won't do anything and sit idle.
If Jason is selected and he finds out that the bulb is lit, he will add one to his count and will switch off the bulb. If the bulb is already switched off, he will sit there idly. In such a manner when his count reaches to 99, he will tell the warden that every prisoner has now been to the room.
Let us craft out the solution in simpler terms. Whenever a prisoner goes inside the room, he simply switches on the bulb if it is off. Thus one prisoner will only light the bulb once. When Jason finds out that the bulb it on, he will know that this has been done by a new prisoner and he will add one to his count. He will keep doing this till his count reaches 99. 99 because, he already has been in the room which makes a total of 100. Thus it is a full proof plan that will definitely set them all free.