23 selected prisoners are summoned by the warden. He gives them a choice of playing a game with him that might ensure their escape from the prison or might as well lead them towards painful death. The prisoners think that this is the only chance for them to be free again and agrees to him.
The warden tell them that there is a room which has just two switches which are labelled 1 or 2. The switches may be up or down and the condition is not known at present. They are not connected to anything. The warden may select any prisoner on any day and send him to the switch room. The prisoner will have to select any one switch and reverse its position i.e. if it is up, he will turn it down and if it is down, he will turn it up. He can and must only flip one switch and then he will be confined to his cell again.
The warden may choose the same prisoner more than one time and he will be choosing completely randomly. But at a certain point of time, everyone will have visited the switch room. And at any time, the prisoners may declare that everyone has visited the room at least once. If they will be true, they will be set free but if they will be wrong, they will be killed.
The warden gives them an hour to plan any kind of strategy and then they will be confined to their respective cells and will never be allowed to meet. What strategy can help them be free?
Solution:
Everyone will appoint any one person as a leader. Now everyone must follow some steps. Every prisoner will flip the first switch up at the first opportunity and also at the second opportunity. If the first switch is already up or they have flipped it up two times already, then they will flip the second switch. The leader however will have a different routine. He is the only one who will flip the switch down the first switch. Suppose if the switch is already down, he will flip the second switch. Also he will keep a count and when he has flipped the first switch down 44 times, he will declare that every prisoner has visited the room.
This is because once the leader has flipped down the switch 44 times, he will know that everyone has visited the room. If the switch was down initially, the other 22 prisoners will turn it up two times. If the first switch was already up, there will be one prisoner who will flip the switch up only once and the rest will do it twice.
Now this trick won't work when the leader has flipped the switch 23 times. Consider the fact that it is possible that 12 prisoners randomly and the leader have been taken to the switch room 24 times and the rest have not been taken till then. Remember that the first switch might have been up in the beginning itself. Thus the prisoners must flip the switch up twice. If they do it just once, the leader will never know whether to count till 22 or 23.