The 100 Prisoner's problem
February 21, 2016 at 9:45 am
(This post was last modified: February 21, 2016 at 11:28 am by Aractus.)
Here's an interesting maths puzzle...
"The director of a prison offers 100 death row prisoners, who are numbered from 1 to 100, a last chance. A room contains a cupboard with 100 drawers. The director randomly puts one prisoner's number in each closed drawer. The prisoners enter the room, one after another. Each prisoner may open and look into 50 drawers in any order. The drawers are closed again afterwards. If, during this search, every prisoner finds his number in one of the drawers, all prisoners are pardoned. If just one prisoner does not find his number, all prisoners die. Before the first prisoner enters the room, the prisoners may discuss strategy—but may not communicate once the first prisoner enters to look in the drawers. What is the prisoners' best strategy?" (Flajolet & Sedgewick 2009 as cited on Wikipedia).
To illustrate this, here is a genuinely random table of 100 numbers 1-100 numbered 1-100:
001 002 003 004 005 006 007 008 009 010
{063} {072} {099} {092} {059} {085} {034} {087} {003} {027}
011 012 013 014 015 016 017 018 019 020
{081} {019} {079} {025} {060} {010} {082} {070} {005} {073}
021 022 023 024 025 026 027 028 029 030
{017} {086} {006} {018} {033} {065} {094} {008} {011} {029}
031 032 033 034 035 036 037 038 039 040
{075} {021} {088} {100} {037} {052} {032} {093} {084} {091}
041 042 043 044 045 046 047 048 049 050
{062} {076} {089} {071} {002} {083} {020} {035} {031} {096}
051 052 053 054 055 056 057 058 059 060
{074} {014} {095} {077} {004} {024} {090} {066} {013} {051}
061 062 063 064 065 066 067 068 069 070
{057} {015} {049} {038} {042} {064} {097} {040} {043} {061}
071 072 073 074 075 076 077 078 079 080
{068} {023} {053} {007} {067} {036} {028} {045} {009} {056}
081 082 083 084 085 086 087 088 089 090
{022} {016} {046} {080} {030} {012} {058} {069} {047} {048}
091 092 093 094 095 096 097 098 099 100
{055} {026} {039} {098} {041} {050} {078} {054} {001} {044}
The chance of guessing right by chance alone is ½100 which in layman's terms is impossible. But there is a strategy that gives the prisoners a realistic chance of success. See if you can come up with the answer, and if not read on. Just some things to keep in mind:
The prisoners can not alter anything in the room, each time a prisoner goes in and opens drawers in a search for his number, and leaves, he is returned to cell to wait, the room is reset to how it was before he entered. No information about the numbers inside the drawers can be known or passed to the prisoners waiting to enter the room.
Obviously no matter what strategy you use the first prisoner always has a 50:50 chance of being right. So while there's no way to guarantee success, as mentioned above there is a strategy that gives them a very real chance.
The strategy is surprisingly simple. Simply start at your number, open the drawer, if you find your number tell the guard, otherwise use the number in the drawer to select the next drawer and repeat until your 50 guesses are used up.
Why does this strategy work?
It's simple, because doing this creates a closed cycle of numbers. Eventually you have to find your number with this method, and you will find it only once you reach the end of the loop. The cycle could be as small as one number (i.e. your number is in the drawer with your number on it), or in the worst-case there could be a cycle of all 100 numbers. But whatever the case if you start on the drawer with your number on it you are guaranteed to eventually come to a drawer with your number in it, and doing this will ignore all the numbers that aren't part of the loop. So if the biggest loop contains 50 numbers or less then the prisoners will be successful using this strategy.
Look at what happens if we use this strategy with the numbers I generated randomly above (and yes they are genuinely random and I did not change any numbers. I computed them on Stat Trek and then labelled them 1-100):
Prisoner 1 enters and has the following guesses,
The next prisoner to enter that is not in this first loop of numbers is prisoner 4. So...
Prisoner 4 enters and has the following guesses,
So now we have a second cycle, this time of 35 numbers. In total these two cycles will see 64 prisoners successfully find their number, and that leaves just 36 remaining. That means there now cannot be a cycle of numbers larger than 36 numbers, therefore the remaining 36 prisoners will also find their numbers without exhausting their guesses.
Prisoner 8 is the next to enter that's in neither of those number loops.
Prisoner 8 enters and has the following guesses,
Alright, that now just leaves four remaining prisoners not in one of those three large loops: 46, 50, 83, and 96. They exist in two micro loops: 46-83 and 50-96. So when those four prisoners enter and start on their numbers, they each take two guesses to find their prisoner number inside a drawer.
Here's the reason why this method gives the prisoners a chance of success:
As you can see in the graph, it all comes down to the chance of the longest cycle being 50 numbers or less. This strategy works 100% of the time when the biggest cycle is 50 or less, and fails 100% of the time when the biggest cycle is 51 or more. The actual probability for 100 prisoners is approximately 31%. So the prisoner have a 31% chance of all being pardoned if they follow this strategy, and I had a 31% chance that my random generated numbers would show an example of success as opposed to an example of failure. This strategy is so efficient that even as the number of prisoners approaches infinity they still have a greater than 30% chance of success if they follow it. For example, if this were a huge prison with 10,000 inmates, and their prisoner numbers were hidden in a bank of 10,000 drawers for them to each have 5,000 guesses at it would still give them a reasonable chance of success of 30-31%. Of course that's assuming each of them could concentrate long enough to look through 5,000 drawers without accidentally missing their number, or leaving the cycle, but human error aside it would still work.
What this puzzle demonstrates is that even a seemingly impossible problem can be solved by finding the most mathematically efficient route.
Of course in the real world things might work differently. The prison warden might have figured this out, and artificially seen to it that there's a 100-number cycle (not hard to do, you just join the smaller cycles together, for example take number 66 out of drawer 58, take number 45 out of 78, and take number 76 out of drawer 42, and then place 76 in 78, 45 in 42, and 76 in 58, and that would join all three of the large cycles in my table together). Or he might generate a new random assignment of numbers each time, which would also kill any chance the prisoner's have of successfully finding their numbers. Another thing that might happen is you get prisoners that refuse to follow the optimal plan - or those who not willing to use all 50 guesses following the plan. For example, you could have a few prisoners open 46 drawers before they decide the strategy is stupid and they're going to guess whatever they want. That's not going to affect their individual chances of selecting their numbers, but it will crush the overall chance for the team since if they leave a winning cycle of say 48 numbers early, then the fact that the other 47 prisoners who's numbers are in the cycle successfully navigated their way to their number is now irrelevant. Or you could have a smart-ass who refuses to open any drawers, or decides to break the rules in some way, also ruining it for everyone!
"The director of a prison offers 100 death row prisoners, who are numbered from 1 to 100, a last chance. A room contains a cupboard with 100 drawers. The director randomly puts one prisoner's number in each closed drawer. The prisoners enter the room, one after another. Each prisoner may open and look into 50 drawers in any order. The drawers are closed again afterwards. If, during this search, every prisoner finds his number in one of the drawers, all prisoners are pardoned. If just one prisoner does not find his number, all prisoners die. Before the first prisoner enters the room, the prisoners may discuss strategy—but may not communicate once the first prisoner enters to look in the drawers. What is the prisoners' best strategy?" (Flajolet & Sedgewick 2009 as cited on Wikipedia).
To illustrate this, here is a genuinely random table of 100 numbers 1-100 numbered 1-100:
001 002 003 004 005 006 007 008 009 010
{063} {072} {099} {092} {059} {085} {034} {087} {003} {027}
011 012 013 014 015 016 017 018 019 020
{081} {019} {079} {025} {060} {010} {082} {070} {005} {073}
021 022 023 024 025 026 027 028 029 030
{017} {086} {006} {018} {033} {065} {094} {008} {011} {029}
031 032 033 034 035 036 037 038 039 040
{075} {021} {088} {100} {037} {052} {032} {093} {084} {091}
041 042 043 044 045 046 047 048 049 050
{062} {076} {089} {071} {002} {083} {020} {035} {031} {096}
051 052 053 054 055 056 057 058 059 060
{074} {014} {095} {077} {004} {024} {090} {066} {013} {051}
061 062 063 064 065 066 067 068 069 070
{057} {015} {049} {038} {042} {064} {097} {040} {043} {061}
071 072 073 074 075 076 077 078 079 080
{068} {023} {053} {007} {067} {036} {028} {045} {009} {056}
081 082 083 084 085 086 087 088 089 090
{022} {016} {046} {080} {030} {012} {058} {069} {047} {048}
091 092 093 094 095 096 097 098 099 100
{055} {026} {039} {098} {041} {050} {078} {054} {001} {044}
The chance of guessing right by chance alone is ½100 which in layman's terms is impossible. But there is a strategy that gives the prisoners a realistic chance of success. See if you can come up with the answer, and if not read on. Just some things to keep in mind:
The prisoners can not alter anything in the room, each time a prisoner goes in and opens drawers in a search for his number, and leaves, he is returned to cell to wait, the room is reset to how it was before he entered. No information about the numbers inside the drawers can be known or passed to the prisoners waiting to enter the room.
Obviously no matter what strategy you use the first prisoner always has a 50:50 chance of being right. So while there's no way to guarantee success, as mentioned above there is a strategy that gives them a very real chance.
The strategy is surprisingly simple. Simply start at your number, open the drawer, if you find your number tell the guard, otherwise use the number in the drawer to select the next drawer and repeat until your 50 guesses are used up.
Why does this strategy work?
It's simple, because doing this creates a closed cycle of numbers. Eventually you have to find your number with this method, and you will find it only once you reach the end of the loop. The cycle could be as small as one number (i.e. your number is in the drawer with your number on it), or in the worst-case there could be a cycle of all 100 numbers. But whatever the case if you start on the drawer with your number on it you are guaranteed to eventually come to a drawer with your number in it, and doing this will ignore all the numbers that aren't part of the loop. So if the biggest loop contains 50 numbers or less then the prisoners will be successful using this strategy.
Look at what happens if we use this strategy with the numbers I generated randomly above (and yes they are genuinely random and I did not change any numbers. I computed them on Stat Trek and then labelled them 1-100):
Prisoner 1 enters and has the following guesses,
- Opens drawer 1
- Opens drawer 63
- Opens drawer 49
- Opens drawer 31
- Opens drawer 75
- Opens drawer 67
- Opens drawer 97
- Opens drawer 78
- Opens drawer 45
- Opens drawer 2
- Opens drawer 72
- Opens drawer 23
- Opens drawer 6
- Opens drawer 85
- Opens drawer 30
- Opens drawer 29
- Opens drawer 11
- Opens drawer 81
- Opens drawer 22
- Opens drawer 86
- Opens drawer 12
- Opens drawer 19
- Opens drawer 5
- Opens drawer 59
- Opens drawer 13
- Opens drawer 79
- Opens drawer 9
- Opens drawer 3
- Opens drawer 99 SUCCESS!
The next prisoner to enter that is not in this first loop of numbers is prisoner 4. So...
Prisoner 4 enters and has the following guesses,
- Opens drawer 4
- Opens drawer 92
- Opens drawer 26
- Opens drawer 65
- Opens drawer 42
- Opens drawer 76
- Opens drawer 36
- Opens drawer 52
- Opens drawer 14
- Opens drawer 25
- Opens drawer 33
- Opens drawer 88
- Opens drawer 69
- Opens drawer 43
- Opens drawer 89
- Opens drawer 47
- Opens drawer 20
- Opens drawer 73
- Opens drawer 53
- Opens drawer 95
- Opens drawer 41
- Opens drawer 62
- Opens drawer 15
- Opens drawer 60
- Opens drawer 51
- Opens drawer 74
- Opens drawer 7
- Opens drawer 34
- Opens drawer 100
- Opens drawer 44
- Opens drawer 71
- Opens drawer 68
- Opens drawer 40
- Opens drawer 91
- Opens drawer 55 SUCCESS!
So now we have a second cycle, this time of 35 numbers. In total these two cycles will see 64 prisoners successfully find their number, and that leaves just 36 remaining. That means there now cannot be a cycle of numbers larger than 36 numbers, therefore the remaining 36 prisoners will also find their numbers without exhausting their guesses.
Prisoner 8 is the next to enter that's in neither of those number loops.
Prisoner 8 enters and has the following guesses,
- Opens drawer 8
- Opens drawer 87
- Opens drawer 58
- Opens drawer 66
- Opens drawer 64
- Opens drawer 38
- Opens drawer 93
- Opens drawer 39
- Opens drawer 84
- Opens drawer 80
- Opens drawer 56
- Opens drawer 24
- Opens drawer 18
- Opens drawer 70
- Opens drawer 61
- Opens drawer 57
- Opens drawer 90
- Opens drawer 48
- Opens drawer 35
- Opens drawer 37
- Opens drawer 32
- Opens drawer 21
- Opens drawer 17
- Opens drawer 82
- Opens drawer 16
- Opens drawer 10
- Opens drawer 27
- Opens drawer 94
- Opens drawer 98
- Opens drawer 54
- Opens drawer 77
- Opens drawer 28 SUCCESS!
Alright, that now just leaves four remaining prisoners not in one of those three large loops: 46, 50, 83, and 96. They exist in two micro loops: 46-83 and 50-96. So when those four prisoners enter and start on their numbers, they each take two guesses to find their prisoner number inside a drawer.
Here's the reason why this method gives the prisoners a chance of success:
As you can see in the graph, it all comes down to the chance of the longest cycle being 50 numbers or less. This strategy works 100% of the time when the biggest cycle is 50 or less, and fails 100% of the time when the biggest cycle is 51 or more. The actual probability for 100 prisoners is approximately 31%. So the prisoner have a 31% chance of all being pardoned if they follow this strategy, and I had a 31% chance that my random generated numbers would show an example of success as opposed to an example of failure. This strategy is so efficient that even as the number of prisoners approaches infinity they still have a greater than 30% chance of success if they follow it. For example, if this were a huge prison with 10,000 inmates, and their prisoner numbers were hidden in a bank of 10,000 drawers for them to each have 5,000 guesses at it would still give them a reasonable chance of success of 30-31%. Of course that's assuming each of them could concentrate long enough to look through 5,000 drawers without accidentally missing their number, or leaving the cycle, but human error aside it would still work.
What this puzzle demonstrates is that even a seemingly impossible problem can be solved by finding the most mathematically efficient route.
Of course in the real world things might work differently. The prison warden might have figured this out, and artificially seen to it that there's a 100-number cycle (not hard to do, you just join the smaller cycles together, for example take number 66 out of drawer 58, take number 45 out of 78, and take number 76 out of drawer 42, and then place 76 in 78, 45 in 42, and 76 in 58, and that would join all three of the large cycles in my table together). Or he might generate a new random assignment of numbers each time, which would also kill any chance the prisoner's have of successfully finding their numbers. Another thing that might happen is you get prisoners that refuse to follow the optimal plan - or those who not willing to use all 50 guesses following the plan. For example, you could have a few prisoners open 46 drawers before they decide the strategy is stupid and they're going to guess whatever they want. That's not going to affect their individual chances of selecting their numbers, but it will crush the overall chance for the team since if they leave a winning cycle of say 48 numbers early, then the fact that the other 47 prisoners who's numbers are in the cycle successfully navigated their way to their number is now irrelevant. Or you could have a smart-ass who refuses to open any drawers, or decides to break the rules in some way, also ruining it for everyone!
For Religion & Health see:[/b][/size] Williams & Sternthal. (2007). Spirituality, religion and health: Evidence and research directions. Med. J. Aust., 186(10), S47-S50. -LINK
The WIN/Gallup End of Year Survey 2013 found the US was perceived to be the greatest threat to world peace by a huge margin, with 24% of respondents fearful of the US followed by: 8% for Pakistan, and 6% for China. This was followed by 5% each for: Afghanistan, Iran, Israel, North Korea. -LINK
"That's disgusting. There were clean athletes out there that have had their whole careers ruined by people like Lance Armstrong who just bended thoughts to fit their circumstances. He didn't look up cheating because he wanted to stop, he wanted to justify what he was doing and to keep that continuing on." - Nicole Cooke
The WIN/Gallup End of Year Survey 2013 found the US was perceived to be the greatest threat to world peace by a huge margin, with 24% of respondents fearful of the US followed by: 8% for Pakistan, and 6% for China. This was followed by 5% each for: Afghanistan, Iran, Israel, North Korea. -LINK
"That's disgusting. There were clean athletes out there that have had their whole careers ruined by people like Lance Armstrong who just bended thoughts to fit their circumstances. He didn't look up cheating because he wanted to stop, he wanted to justify what he was doing and to keep that continuing on." - Nicole Cooke