# Free the prisoners puzzle

1,311.5K Views

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?

ravi Expert Asked on 20th July 2015 in

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.

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.

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.

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
00
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.

Thanks,
Dhruva

dhruva pandey Curious Answered on 8th September 2015.

• ## More puzzles to try-

• ### What is the logic behind these ?

3 + 3 = 3 5 + 4 = 4 1 + 0 = 3 2 + 3 = 4 ...Read More »
• ### Defective stack of coins puzzle

There are 10 stacks of 10 coins each. Each coin weights 10 gms. However, one stack of coins is defective ...Read More »
• ### Which clock works best?

Which clock works best? The one that loses a minute a day or the one that doesn’t work at all?Read More »
• ### (Advanced) Cheryl’s Birthday Puzzle

Paul, Sam and Dean are assigned the task of figuring out two numbers. They get the following information: Both numbers ...Read More »
• ### Five greedy pirates and gold coin distribution Puzzle

Five  puzzleFry ship’s pirates have obtained 100 gold coins and have to divide up the loot. The pirates are all ...Read More »
• ### Magical flowers!!

A  devotee goes to three temples,  temple1, temple2  and temple3  one after the other. In front of each temple, there ...Read More »
• ### Tuesday, Thursday what are other two days staring with T?

Four days are there which start with the letter ‘T‘. I can remember only two of them as “Tuesday , Thursday”. ...Read More »
• ### How could only 3 apples left

Two fathers took their sons to a fruit stall. Each man and son bought an apple, But when they returned ...Read More »
• ### How Many Eggs ?

A farmer is taking her eggs to the market in a cart, but she hits a  pothole, which knocks over ...Read More »
• ### HARD MATHS – How much faster is one train from other Puzzle

Two trains starting at same time, one from Bangalore to Mysore and other in opposite direction arrive at their destination ...Read More »
• ### Most Analytical GOOGLE INTERVIEW Question Revealed

Let it be simple and as direct as possible. Interviewer : Tell me how much time (in days) and money would ...Read More »
• ### Lateral thinking sequence Puzzle

Solve this logic sequence puzzle by the correct digit- 8080 = 6 1357 = 0 2022 = 1 1999 = ...Read More »
• ### How did he know?

A man leaves his house in the morning to go to office and kisses his wife. In the evening on ...Read More »
• ### Pizza Cost Math Brain Teaser

Jasmine, Thibault, and Noah were having a night out and decided to order a pizza for \$10. It turned out ...Read More »
• ### Which letter replaces the question mark

Which letter replaces the question markRead More »
• ### Which room is safest puzzle

A murderer is condemned to death. He has to choose between three rooms. The first is full of raging fires, ...Read More »
• ### Richie’s Number System

Richie established a very strange number system. According to her claim for different combination of 0 and 2 you will ...Read More »
• ### Srabon wanted to pass

The result of math class test came out. Fariha’s mark was an even number. Srabon got a prime!! Nabila got ...Read More »
• ### Become Normal!!

Robi is a very serious student. On the first day of this year his seriousness for study was 1 hour. ...Read More »
• ### Sakib Knows The Number!

Ragib: I got digits of a 2 digit number Sakib: Is it an odd? Ragib: Yes. Moreover, the sum of ...Read More »