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

Mainly Related to Oracle, DBMS , Oracle Stored Procedures, Functions, Oracle 9i Architecture, Redo logs..., Views,

0 Answers   Indian Overseas Bank,


In Bioinformatics, a DNA sequence is made up of a combination of 4 characters, namely “A,C,G,T”. A subsequence of a given sequence of characters a0, a1, …an- 1, is any subset of the characters taken in order, of the form ai0 , ai1 ,…..aik-1 where 0 &#8804; i0 <i1….< ik-1 &#8804; n-1. For example in the sequence “A,C,G,T,G,T,C,A,A,A,A,T,C,G”, we can have subsequences “A,G,T”, “A,C,A,A” and many more. A subsequence is palindromic if it is the same whether read left to right or right to left. For instance, the sequence “A,C,G,T,G,T,C,A,A,A,A,T,C,G”, has many palindromic subsequences, including “A,C,G,C,A” and “A,A,A,A” (on the other hand, the subsequence “A,C,T” is not palindromic). Devise an algorithm (using dynamic programming) that takes a sequence of characters X[0 … n-1] from the alphabet set (A,C,G,T) and returns the (length of the) longest palindromic subsequence. Implement the algorithm in an appropriate language.

1 Answers  


Please describe an example where you used object orientation in one of your programs.

0 Answers  


HOW TO FIND NUMBER OF TWOS IN N!(N FACTORIAL)??

0 Answers  


SELECT A~FTRMI A~AUFNR B~MATNR D~MAKTX B~PSMNG B~WEMNG C~MTART E~CHARG C~MATKL C~SPART R~BWART R~CHARG R~MATNR E~BWART R~BDMNG INTO TABLE ITAB FROM AFKO AS A INNER JOIN AFPO AS B ON A~AUFNR = B~AUFNR * INNER JOIN AFVC AS A1 ON A~AUFPL = A1~AUFPL AND B~DWERK = A1~WERKS INNER JOIN MARA AS C ON B~MATNR = C~MATNR INNER JOIN MAKT AS D ON C~MATNR = D~MATNR INNER JOIN MSEG AS E ON B~MATNR = E~MATNR AND A~AUFNR = E~AUFNR AND B~DWERK = E~WERKS INNER JOIN RESB AS R ON A~AUFNR = R~AUFNR AND E~AUFNR = R~AUFNR AND R~RSNUM = A~RSNUM AND R~WERKS = E~WERKS AND R~BAUGR = E~MATNR INNER JOIN MARA AS C1 ON R~MATNR = C1~MATNR WHERE A~FTRMI IN S_DATE AND A~AUFNR IN S_AUFNR AND C~MTART IN S_TYPE AND C~MATKL = 'T' AND R~BWART ='261' AND E~BWART = '101' AND R~XWAOK ='X' AND B~DWERK = '2000' AND R~XLOEK EQ SPACE AND E~KZBEW ='F' AND D~SPRAS = 'E' AND R~KZEAR = 'X' AND C~MATNR IN S_MATNR. This query gives repetative records from RESB.There must be some common field which i am not taking thats why its giving repetative records. If u find any solution pls lety me know ASAP. Thanks Swati Ghadge

0 Answers  






write a program on c(or)c++(or)java language i.e if i have 5 numbers like (10,24,3,9,15) i want to display highest number from these numbers

2 Answers  


how to convert the data from HTML file to SAS dataset?

0 Answers   Accenture,


what is client server & server? What r types of Joins? explsin it! which types of indexex in sql server? what is triggers?

0 Answers  


if we want to move all the items that are already added in a combobox into an empty list box or vice-versa then how can it possible in vb or C# ?

1 Answers  


can u send some model papers how computer awareness questions are asked in goverment jobs(oriental insurance)to my mail id me.priyankapadma@rediff.com

0 Answers  


Difference between abstract class and Interfaces in Java

9 Answers   Nest, Persistent, Yantro Software,


what is lazy loading in hibernate?Explain in detailed manner?

2 Answers   IBM, TCS,


Categories