Free the prisoners puzzle


The warden meets with 23 new prisoners when they arrive. He tells them, “You may meet today and plan a strategy. But after today, you will be in isolated cells and will have no communication with one another.

“In the prison is a switch room, which contains two light switches labeled 1 and 2, each of which can be in either up or the down position. I am not telling you their present positions. The switches are not connected to anything.

“After today, from time to time whenever I feel so inclined, I will select one prisoner at random and escort him to the switch room. This prisoner will select one of the two switches and reverse its position. He must flip one switch when he visits the switch room, and may only flip one of the switches. Then he’ll be led back to his cell.

“No one else will be allowed to alter the switches until I lead the next prisoner into the switch room. I’m going to choose prisoners at random. I may choose the same guy three times in a row, or I may jump around and come back. I will not touch the switches, if I wanted you dead you would already be dead.

“Given enough time, everyone will eventually visit the switch room the same number of times as everyone else. At any time, anyone may declare to me, ‘We have all visited the switch room.’

“If it is true, then you will all be set free. If it is false, and somebody has not yet visited the switch room, you will all die horribly. You will be carefully monitored, and any attempt to break any of these rules will result in instant death to all of you”

What is the strategy they come up with so that they can be free?

Add Comment

  • 3 Answer(s)

    Team needs a COUNTER(so selects a leader as counter)

    The team nominates a leader. The group agrees upon the following rules so that counting can be done by counter:

    The leader is the only person who will announce that everyone has visited the switch room. All the prisoners (except for the leader) will flip the first switch up at their very first opportunity, and again on the second opportunity. If the first switch is already up, or they have already flipped the first switch up two times, they will then flip the second switch. Only the leader may flip the first switch down, if the first switch is already down, then the leader will flip the second switch. The leader remembers how many times he has flipped the first switch down. Once the leader has flipped the first switch down 44 times, he announces that all have visited the room.

    It does not matter how many times a prisoner has visited the room, in which order the prisoners were sent or even if the first switch was initially up. Once the leader has flipped the switch down 44 times then the leader knows everyone has visited the room. If the switch was initially down, then all 22 prisoners will flip the switch up twice. If the switch was initially up, then there will be one prisoner who only flips the switch up once and the rest will flip it up twice.

    The prisoners can not be certain that all have visited the room after the leader flips the switch down 23 times, as the first 12 prisoners plus the leader might be taken to the room 24 times before anyone else is allowed into the room. Because the initial state of the switch might be up, the prisoners must flip the first switch up twice. If they decide to flip it up only once, the leader will not know if he should count to 22 or 23.

    In the example of three prisoners, the leader must flip the first switch down three times to be sure all prisoners have visited the room, twice for the two other prisoners and once more in case the switch was initially up.

    John123 Expert Answered on 20th July 2015.

    what if prisoner happens to call leader all the time lets say 10 times before calling anybody else  ,,,,,,

    on 8th September 2015.

    If leader is called 10 times continuously he will still be counting 1 as himself.
    Only when The leader will get the Switch up he’ll flip the switch and count 2.

    I agree this might be a never ending process but It is the Only solution.

    on 8th September 2015.

    They can just decide to switch up the first switch once, and the leader counts to 23, cause at 23 he can be certain everyone has been to the room.22 wld B a gamble, and with 23 he cold stay at the safe side

    on 9th September 2016.

    No he can’t. Suppose the switch 1 is initially down. They decide to flip switch 1 only once. 1st prisoner goes and switches on switch 1. Then leader goes and switches off switch 1 and counts 1 then 2nd prisoner goes then the leader and this goes on till the 22nd prisoner and counter reads 22 .
    Now the counter will never go up to 23 as everyone has flipped the switch 1 once and thus the leader would never declare that they all have visited the room.

    on 29th September 2016.
    Add Comment

    The switch #1 is used to COUNT. The #2 is used to PASS.

    The prisoners elect a leader and stablish the following rules and behaviours:

    Only the leader can turn the switch #1 off.

    Only the leader can announce that they all visited the room.

    Leader’s behavior:
    If the switch #1 is on, turn off the switch #1 and count 1 visit more ( # of visits starts from zero).
    If the # of visits is equal to 23 (22 prisoners plus the case were the switch #1 was already on), warns: “We have all visited the switch room”
    If not, flips the switch #2.

    Other’s behavior:
    If the switch #1 is turned off and I never turned the switch #1 on, then turn the switch #1 on.
    If not, flips the switch #2.


    Marcio Oliveira Starter Answered on 22nd September 2015.
    Add Comment

    safest way i could think of if they assign ID’s 1 to 23 to each of the prisoners (they have to remember their ID’s of-course)  and based on their ID
    if (even ) flip switch at ur right and if odd flip switch at ur left.
    Initially switches can be 00 (off off) or 11 (on on)
    Let make a table how switch order changes with every press by each ID’s (they are drawing in group meeting before it starts)
    Person ID        Switch Left – Switch Right
    01.                                                01
    02.                                                11
    03.                                                10
    04.                                                00

    05.                                                01
    06.                                                11
    07.                                                10
    08.                                                00

    09.                                                01
    10.                                                11
    11.                                                10
    12.                                                00

    13.                                                01
    14.                                                11
    15.                                                10
    16.                                                00

    17.                                                01
    18.                                                11
    19.                                                10
    10.                                                00

    11.                                                01
    12.                                                11
    13.                                                10
    14.                                                00

    15.                                                01
    16.                                                11
    17.                                                10
    18.                                                00

    19.                                                01
    20.                                                11
    21.                                                10
    22.                                                00

    23.                                                01
    // again 01
    01.                                                00
    02.                                                10
    03.                                                11
    04.                                                10

    05.                                                11
    06.                                                10
    07.                                                11
    08.                                                01

    and so on ….

    Now you see a pattern doesn’t matter what the initial state of switch is all even ID’s should expect to see the same (00 or 11) in first round and once all 23 visited in second round all odd ID’s will see the switch state same (00 or 11) i.e, once the same person sees the same state (00 or 11) thrice either in order 00 –> 11 –> 00 or 11–> 00 –> 11 i.e, he knows three rounds are done and everyone should have visited it once. So, he can announce the freedom call 😉

    The fact that prisoner can pick ” the same guy three times in a row” – doesn’t matter it will flip back to original state. (00 -> odd person came in thrice  01-> 00 -> 01.) and NOTE : he will see the order 00 -> 00 –>not 00 –> 01 –> so no chance of miss calculations.

    Only thing they have to remember is their ID’s and  once you see 00 –> 11 –> 00 or 11–> 00 –> 11 pattern after u n visits you are good to make a call .

    To me on absolutely safe side if in case u don’t want to miss any corner case you can extend the freedom pattern like –> 00 –> 11 –> 00 –> 11 or 11–> 00 –> 11 –> 00 . Or even bigger if you want to enjoy few more nights in prison.


    dhruva pandey Curious Answered on 8th September 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.
  • More puzzles to try-