views:

602

answers:

15

100 (or some even number 2N :-) ) prisoners are in a room A. They are numbered from 1 to 100.

One by one (from prisoner #1 to prisoner #100, in order), they will be let into a room B in which 100 boxes (numbered from 1 to 100) await them. Inside the (closed) boxes are numbers from 1 to 100 (the numbers inside the boxes are randomly permuted!).

Once inside room B, each prisoner gets to open 50 boxes (he chooses which one he opens). If he finds the number that was assigned to him in one of these 50 boxes, the prisoner gets to walk into a room C and all boxes are closed again before the next one walks into room B from room A. Otherwise, all prisoners (in rooms A, B and C) gets killed.

Before entering room B, the prisoners can agree on a strategy (algorithm). There is no way to communicate between rooms (and no message can be left in room B!).

Find a strategy (algorithm) that maximizes the probability that all prisoners survive. What probability does your algorithm achieve?

Edits:

  • Note that I did ask if it was OK to post puzzles. I'd like to get some feedback from people downvoting if possible!

  • @Ross: doing things randomly (what you call 'no strategy') indeed gives a probability of 1/2 for each prisoner, but then the probability of all of them surviving is 1/2^100 (which is quite low). One can do much better!

  • The prisoners are not allowed to reorder the boxes!

  • Also, be assured that I do have an interesting solution. I'll post it in a week or so :)

  • @Sam Hasler: all prisoners are killed the first time a prisoner fails to find his number. And no communication is possible.

  • Hint: one can save more than 30 prisoners on average, which is much more that (50/100) * (50/99) * [...] * 1

  • @Rob Cooper: I get your point (no point in yelling!), however it reflects your opinion (and that of some others I'm sure), and I don't yet see a consensus on that matter. I do respect your opinion (didn't vote on your answer, or on any other by the way), but I'd really like to have this clarified (in the FAQ for example...).

  • @Jorge: I still didn't get into the details of your solution, but I believe that you can indeed do it this way. However, this is basically using time to communicate. The solution I have in mind doesn't involve any kind of communication (so people can't rely on time, for example).

  • @chakrit: it would help if you provided the probability that your method achieves. In case it's too complicated to work out, running simulations (Monte-Carlo like) would give you an estimate!

  • @jbettis: this is indeed the solution I had in mind (and believe me or not, but I found it myself when presented with the problem). As for the wording, I'm sorry but I'm not a native English speaker. For the specific wordings you refer to: for me, saving more that 30 on average is equivalent to your wording; also the problem is the same if you kill all prisoners as soon as one fails...

A: 

Maybe it is because you asked it around an hour ago and the guy down voting didn't actually see or read yoor previous questions.

ps:in case it's not clear, I'm not the guy that downvoted you..

paan
A: 

Well to start with on entering room B each prisoner has the probability of 50/100 (or 1/2) to get his number. With no strategy this gives the prisoners (1/2)/100 (or 0.005 chance of survivial).

Are the prisoners allowed to re-order the boxes?

Ross
A: 

Having just googled, this is a quite interesting problem.

DrPizza
+1  A: 

Implement a sorting algorithm and sort the boxes according to the numbers inside them.

First prisoner sorts 50 boxes, and the second prisoner sorts the other 50 and merges with the first one. (Note that the second prisoner can guess the values inside the first 50 boxes)

After the 2nd prisoner, all of the boxes will be in a sorted order !!!

Everybody else can open the boxes containing their numbers easily then.

Niyaz
A: 

I down-voted because I think this is not a question that is related to software development.

And I don't care if you asked for permission in another thread. In fact that one was off-topic as well.

Just let the system do the work of filtering out the good and bad questions. ;)

Edit: Btw, you can abstract nearly everything so that it becomes an issue which is related to programming. :)

Cheer up!

FantaMango77
A customer might not tell you the exact mathematical or programmatic details of what he wants some software to do. I think it's important for a programmer to read a plain English problem description and be able to formulate a solution.
Benny Jobigan
+9  A: 

I think the whiners who want the site to be nothing more interesting than "pls hlp me rite a regexp. thank u!!11!" should shut the hell up.

A programming site that doesn't permit discussion of algorithms and mathematics is a waste of everyone's time.

DrPizza
+3  A: 

I find a low tech solution to this type of problem is always the best way to go.

first we make some assumptions about the situation

  • The prisoners are not all programmers or mathematicians
  • They don't want to die
  • The guards are well armed

So with a 0.005% chance that they will see tomorrow, there is a very simple and low tech solution to this problem. RIOT

its all about losses v potential gain, the chances are the prisoners far out number the guards, and using each other as human shields, as they are all dead men anyway if they don't, they can increase the chances they will over power a guard, once they have his weapon there chance goes up, helping them over power more guards to get more fire power to further increase there survival rate. once the guards realise what's happening, they will probably run for the hills and lock down the prison, this will give the media a heads up and then its a human rights issue.

Re0sless
A: 

Maybe I'm not reading it right, but the question seems to be badly constructed or missing information.

If he finds the number that was assigned to him in one of these 50 boxes, the prisoner gets to walk into a room C and all boxes are closed again before the next one walks into room B from room A. Otherwise, all prisoners (in rooms A, B and C) gets killed.

Does the last sentence there mean that all prisoners are killed the first time a prisoner fails to find their number? If not, what happens to prisoners that don't find their number?

If no communication is possible, and whenever a prisoner enters room B it is always in an identical state then there is no possibility for a strategy.

The prisoners could could say before they leave room A which number box they are going to open. But without subsequent prisoners knowing whether they were successful or not (assuming failure for one isn't failure for all) when the next prisoner enters room B they still have the same odds of picking their number as the previous prisoner (always 1:100).

If failure for one is failure for all, then by knowing which box the previous prisoners opened, and by dint of the fact that they haven't all been killed, each successive prisoner could reduce the odds of picking the wrong box by one box. i.e. 1:100 for the first prisoner, 1:99 for the second, down to 1:1 for the last.

Sam Hasler
A: 

The prisoners could agree that prisoner 1 open boxes 1-50.

If they're all still alive, they agree that the next prisoner opens boxes 2-51. (the 2 is arbitrary, but simple to remember this rule) His odds of surviving given that P1 survived are now 50/99. You want to eliminate opening a box when you know that the previous guy found his.

I don't know if that's optimal, but it's lot better than random.

The probability of surviving that looks like

50/100 * 50/99 * 50/98 *. . .50/51 * 1

Baltimark
+1  A: 

I don't know if this is allowed but the best approximation I can find is:

EDIT: Ok, I think this makes it. Of course I'm treating this as a computing problem, I don't think any prisioner will be able to perform this, although is pretty straight forward if you don't.

Find the first 50 primes, let's asume we hold them in an array called primes.

  • The first prissioner enters room B and opens the first box and finds the number m.
  • Wait primes[1]^m (that would be 3^m)
  • Open box 2 and read the number --> n
  • Wait (primes[2]^n - 1) * primes[1]^m, that would be (5^n - 1) * 3^m and the total time he has been waiting would be 3^n * 5^n

Repeat. After the first prisioner the total time for him would be: 3^m * 5^n * 7^p ... = X

Before the second prisioner enters the room factorize X. You know beforehand the prime numbers that have been used so the factorization is trivial. Doing so you obtain m, n, p, etc so the second prisioner knows every box/number combination the previous prisioner used.

The probability of the first one getting everybody killed is 1/2, the second one will have a 50 / (100 - n) (being n the numbers of attemps of the first one) the third one will have 50 / (100 - n - m) (if n + m = 100 then all positions are known) and so on.

Obviously the next prissioner must skip the already known boxes (except for the last choice if the box which contains his number is already known)

I don't know what's the exact possibility as it dependes on how many choices they have to do but I'd say it's pretty high.

EDIT: Rereading, if the prissioner does not have to stop when he obtains his number then the probability for the whole group is vastly improved, exactly 50%.

EDIT2: @OysterD see it this way. If the first prisioner can open 50 boxes then the second one know if its number is in any of that boxes. If it is, then he can open other 49 (and by doing so learning the box/number comination of the 100 boxes) and finally open his one. So if the first prissioner succeds then everyone succeds. Remember that each prisioner provides a way for the other to know exactly the boxes/number combination for every box he opens.

Jorge Córdoba
A: 

I think since no communication is possible, the best strategy would involve

distributing the probability of each prisoners as evenly as possible

Am I on the right path or not?

Information available for each prisoner:

  • The number of survivied prisoners, so if you have an efficient box picking system that utilizes the order any prisoner enters room B, then a strategy is definitely possible
  • Which boxes the earlier prisoners picked. Of course, no communication is possible during the run and it wouldn't be possible to remember any 100s box picking permutation. But you could use this information to compute in a system before the run starts.

My take:

  1. Draw a table of numbers with 2 columns, the first column contains the box number (from box #1 to box#100). Each prisoner then gets to pick 50 boxes and whatever box they pick, they should put 1 mark on the corresponding row in the second column.
  2. All prisoners are however required to never pick any box twice. And no box may be marked more than 50. Some prisoners may get less options than others since some box may get filled to 50 marks first.
  3. When a prisoner is moved to room B he/she opens whatever boxes he has marked on.
chakrit
A: 

Same concept.

Aonther take:

  1. Write down a list of the first 100 binary numbers which has fifty 1s and fifty 0s.
  2. Sort them from lowest to highest.
  3. Prisoner #1 gets the first number, prisoner #2 gets the second, prisoner #3 gets the third and so on...
  4. Each prisoner remembers his/her binary number.
  5. When any prisoner is moved to room B, he/she then match the binary digits of the number he remembered with each of the box, the highest bit is matched with the leftmost box, the next highest bit is matched with the second leftmost box ... the lowest bit is matched with the rightmost box.
  6. He/she opens whatever boxes matched with 1 and leave closed boxes matched with 0.

This would minimizes the probability because early prisoners will get digits that are different from the later prisoners and prisoners which has number close together would get digits close together. This doesn't guarantee survivability but if the early prisoners do survive, chances are the later prisoners would have a higher probability of surviving as well.

I haven't thought out the exact figures and rationale though, but this is one quick solution I can think of at the moment.

chakrit
A: 

If all prisoners are killed when someone fails to find their number then you either save 100 or 0. There is no way to save 30 people.

Jeremy
+4  A: 

This puzzle is explained at http://www.math.princeton.edu/~wwong/blog/blog200608191813.shtml and that person does a much better job of explaining the problem.

The "all prisoners are killed" statement is wrong. The "you can save 30+ on average" is also wrong, the article says that 30% of the time you can save 100% of the prisoners.

If I had more karma, I would vote down this question.

Jeremy
A: 

There aren't any time limits in the question so I suggest that prisoners should decide to take 1 hour per box and open them in the order presented. If the second prisoner is allowed into the room after 2 hours then he knows that the first prisoner found his own number in box 2. Therefore he knows to skip box 2 in his sequence and opens boxes 1, 3, 4...51 First prisoners odds on losing are 50/100 Give that the first prisoner survived then the second prisoners chance of winning are 50/99 So answer appears to be ((50 ^51)49!)/100! which according to google makes 2.8910^-9 which is pretty much nil So even if the prisoners knew the boxes the previously lucky ones found their number in there'd be no hope