This is a puzzle question ....

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 A and B, each of which can be in either the
'on' or the 'off' 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 move one, but
only one of the switches. He can't move both but he can't
move none either. Then he'll be led back to his cell.

"No one else will enter the switch room until I lead the
next prisoner there, and he'll be instructed to do the same
thing. 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.

"But, given enough time, everyone will eventually visit the
switch room as many times as everyone else. At any time
anyone of you may declare to me, 'We have all visited the
switch room.' and be 100% sure.

"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 be fed to the alligators."

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

Answers were Sorted based on User's Feedback



This is a puzzle question .... The warden meets with 23 new prisoners when they arrive. He tells..

Answer / mahesh shiwani

The team nominates a leader. The group agrees upon the
following rules:

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 when
possible, but only for their first two visits to the room.
If the first switch is already up, or they have already
flipped the first switch twice, they will then on flip the
second switch. Only the leader may flip the first switch
down, and 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 switch was
flipped up by the warden. In the example of three prisoners,
the leader must flip the first switch down four times to be
sure all prisoners have visited the room.

Is This Answer Correct ?    29 Yes 14 No

This is a puzzle question .... The warden meets with 23 new prisoners when they arrive. He tells..

Answer / adrian may

They all have to signal twice, because the first signal the
caller sees might just have been that the warden left the
switch on to begin with. In that case he'll see 45
altogether if he waits long enough. But maybe the switch
was off to begin with and he only gets 44. If one prisoner
had never been in, the most the caller could see is 43. If
each prisoner only signals once, you can't tell if somebody
is still waiting when you see 22.

Is This Answer Correct ?    5 Yes 1 No

This is a puzzle question .... The warden meets with 23 new prisoners when they arrive. He tells..

Answer / z

the problem is that the leader will never know whether the
switch was up or down at the beggining. So he has to wait
until he will switch it down 23 times(or 45, because if its
only 44 he wont know if the last prisoner has visited the
switch room, its the same thimg).But in case the switch was
down at the beginning he will have to wait forever for the
23th or 45th time and that will never happen. So there's no
way with this solution that he can be absolute sure(except
ofcourse if one day he switches it down for the 23th or 45th
time respectively)

Is This Answer Correct ?    1 Yes 1 No

This is a puzzle question .... The warden meets with 23 new prisoners when they arrive. He tells..

Answer / pawan

THere are two cases : 1) switch 1 is on and 2)switch 1 is
off. And all except leader will on the first switch if it of
only during their first visit. The position of second switch
i not necessary. 1st case : If the leader goes first he will
make the switch off. so the remaining if goes will turn it
on...so 22 will be wrong because leader started with it so
he cannot be sure after turning off 22 times that all have
visited because therse possibility that one of them have not
visited. If leader does not go first then 22 is enough ...to
be same he tells after 23 switches......case 2: it doesnt
matter if leader is sent first or later...after 23 he can
safely say all have visited

Is This Answer Correct ?    0 Yes 0 No

This is a puzzle question .... The warden meets with 23 new prisoners when they arrive. He tells..

Answer / dave peck

The team nominates a leader. The group agrees upon the
following rules:

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 when
possible, but only for their first visit to the room.
If the first switch is already up, or they have already
flipped the first switch twice, they will then on flip the
second switch. Only the leader may flip the first switch
down, and 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 23 times (once for
each of the other 22 prisoners, and once just in case it
started in the up position), 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 switch was
flipped up by the warden.

Is This Answer Correct ?    1 Yes 3 No

This is a puzzle question .... The warden meets with 23 new prisoners when they arrive. He tells..

Answer / samy

The above answer is correct. But not optiomized. Onr small
correction. Everyone need to Flip the first switch only
once. And leader Need to Flip the first switch 22 times.

Is This Answer Correct ?    9 Yes 32 No

Post New Answer

More Programming Languages AllOther Interview Questions

Differevce between arrays and array builders?

0 Answers  


if there are n nodes in a binary tree, how many null pointers are there?

4 Answers   Hughes,


Difference between debugging, running, executing of an application

0 Answers   HCL,


what are all the validation we need to perform in data stage?

0 Answers  


Urgent Openings for Java and .NET ( India, Singapore, Australia, Japan)

6 Answers   CTS,






hi this is uday i want prepare for nic exam if any one have previous question papers please send me or atlest guide me how to prepare my ID is udaykiran4u@in.com

0 Answers  


what is difference between sap and java ?

1 Answers  


what is throws keyword

1 Answers   IBM,


could you please tell me how to draw the calibration curve for HPLC {the software which we are using}?

0 Answers  


if 3 duplicate records, by keeping one original and one duplicate record, and how to delete remaining 2 duplicates in sql server 2008

0 Answers  


design a counter with the following repeated binary sequence: 0, 1, 2, 3, 4, 5, 6, 7, 8 using JK Flip Flop.

3 Answers   College School Exams Tests, IBD, IBM, Ignou, IIIT, Nortech, TCS, UOS,


What Is The Difeerence Between C & C++

2 Answers   HCL,


Categories