pdf

Prisoner Problems
Tyler Seacrest
University of Nebraska-Lincoln
December 3, 2010
The Setup
The Setup
One day, when the warden of Puzzlania maximum security prison is
bored, he decides to subject all his prisoners to a devious mathematical
game. They are free to discuss strategy beforehand, but once the game
begins they cannot communicate (unless otherwise specified in the rules).
The Warden will detect any cheating of the rules, no matter how clever.
Should they win, they will all be freed. However, if they lose, they will
face a fate worse than death:
The Setup
One day, when the warden of Puzzlania maximum security prison is
bored, he decides to subject all his prisoners to a devious mathematical
game. They are free to discuss strategy beforehand, but once the game
begins they cannot communicate (unless otherwise specified in the rules).
The Warden will detect any cheating of the rules, no matter how clever.
Should they win, they will all be freed. However, if they lose, they will
face a fate worse than death: they will be forced to watch the next M.
Night Shyamalan movie.
Line of Hats
Line of Hats
I
Each prisoner gets a hat, either red or blue, without knowing the
color of his or her own hat.
Line of Hats
I
Each prisoner gets a hat, either red or blue, without knowing the
color of his or her own hat.
I
They are lined up so each prisoner can see the colors of the hats to
the right, but not the hats to the left.
Line of Hats
I
Each prisoner gets a hat, either red or blue, without knowing the
color of his or her own hat.
I
They are lined up so each prisoner can see the colors of the hats to
the right, but not the hats to the left.
I
Sequencially starting on the left, each prisoner is asked what the
color of his own hat is.
Line of Hats
I
Each prisoner gets a hat, either red or blue, without knowing the
color of his or her own hat.
I
They are lined up so each prisoner can see the colors of the hats to
the right, but not the hats to the left.
I
Sequencially starting on the left, each prisoner is asked what the
color of his own hat is.
I
Once the game begins, the prisoners cannot communicate in anyway
except to hear the guesses of prisoners before them in the line.
Line of Hats
I
Each prisoner gets a hat, either red or blue, without knowing the
color of his or her own hat.
I
They are lined up so each prisoner can see the colors of the hats to
the right, but not the hats to the left.
I
Sequencially starting on the left, each prisoner is asked what the
color of his own hat is.
I
Once the game begins, the prisoners cannot communicate in anyway
except to hear the guesses of prisoners before them in the line.
I
Only those who answer correctly are freed.
Line of Hats
I
Each prisoner gets a hat, either red or blue, without knowing the
color of his or her own hat.
I
They are lined up so each prisoner can see the colors of the hats to
the right, but not the hats to the left.
I
Sequencially starting on the left, each prisoner is asked what the
color of his own hat is.
I
Once the game begins, the prisoners cannot communicate in anyway
except to hear the guesses of prisoners before them in the line.
I
Only those who answer correctly are freed.
If there are n prisoners, how many can be guaranteed to be freed?
Line of Hats
Line of Hats
I
We cannot guarantee that the first prisoner will be freed.
Line of Hats
I
We cannot guarantee that the first prisoner will be freed. however
Line of Hats
I
We cannot guarantee that the first prisoner will be freed. however
I
We can save the second prisoner: have the first prisoner guess the
color of the second prisoner’s hat.
Line of Hats
I
We cannot guarantee that the first prisoner will be freed. however
I
We can save the second prisoner: have the first prisoner guess the
color of the second prisoner’s hat.
I
Now the third cannot be saved, but if the third guesses the color of
the fourth prisoner, the fourth prisoner can be saved.
Line of Hats
I
We cannot guarantee that the first prisoner will be freed. however
I
We can save the second prisoner: have the first prisoner guess the
color of the second prisoner’s hat.
I
Now the third cannot be saved, but if the third guesses the color of
the fourth prisoner, the fourth prisoner can be saved.
I
Thus, we can save half the prisoners.
Line of Hats
I
We cannot guarantee that the first prisoner will be freed. however
I
We can save the second prisoner: have the first prisoner guess the
color of the second prisoner’s hat.
I
Now the third cannot be saved, but if the third guesses the color of
the fourth prisoner, the fourth prisoner can be saved.
I
Thus, we can save half the prisoners.
Line of Hats
I
We cannot guarantee that the first prisoner will be freed. however
I
We can save the second prisoner: have the first prisoner guess the
color of the second prisoner’s hat.
I
Now the third cannot be saved, but if the third guesses the color of
the fourth prisoner, the fourth prisoner can be saved.
I
Thus, we can save half the prisoners.
Can we do better?
Prisoner’s Dilemma
I
Two conspirators, Alice and Bob, are asked, in separate
rooms, to rat on the other.
I
Depending on what they say, they will get the following prison
sentences:
Alice rats
Alice stays mum
I
Bob rats
4 years \ 4 years
5 years \ None
Bob stays mum
None \ 5 years
1 year \ 1 year
Probably the most famous “prisoner problem”.
Back to the line of hats
I
Each prisoner got a hat, either red or blue, without knowing the
color of his or her own hat.
I
They were lined up so each prisoner could see the colors of the hats
to the right, but not the hats to the left.
I
Sequencially starting on the left, each prisoner is asked what the
color of his own hat is.
I
Once the game begins, the prisoners cannot communicate in anyway
except to hear the guesses of prisoners before them in the line.
I
Only those who answer correctly are freed.
Back to the line of hats
I
Each prisoner got a hat, either red or blue, without knowing the
color of his or her own hat.
I
They were lined up so each prisoner could see the colors of the hats
to the right, but not the hats to the left.
I
Sequencially starting on the left, each prisoner is asked what the
color of his own hat is.
I
Once the game begins, the prisoners cannot communicate in anyway
except to hear the guesses of prisoners before them in the line.
I
Only those who answer correctly are freed.
If there are n prisoners, how many can be guaranteed to be freed?
Line of Hats Solution
n − 1 prisoners can be saved:
Line of Hats Solution
n − 1 prisoners can be saved:
I
The first prisoner says red if he sees an even number of red
hats, and blue otherwise.
Line of Hats Solution
n − 1 prisoners can be saved:
I
The first prisoner says red if he sees an even number of red
hats, and blue otherwise.
I
The second prisoner can determine her hat color from this
information.
Line of Hats Solution
n − 1 prisoners can be saved:
I
The first prisoner says red if he sees an even number of red
hats, and blue otherwise.
I
The second prisoner can determine her hat color from this
information.
I
The third prisoner can determine his hat color from what the
first and second prisoners said.
Line of Hats Solution
n − 1 prisoners can be saved:
I
The first prisoner says red if he sees an even number of red
hats, and blue otherwise.
I
The second prisoner can determine her hat color from this
information.
I
The third prisoner can determine his hat color from what the
first and second prisoners said.
I
etc.
Line of Hats Solution
n − 1 prisoners can be saved:
I
The first prisoner says red if he sees an even number of red
hats, and blue otherwise.
I
The second prisoner can determine her hat color from this
information.
I
The third prisoner can determine his hat color from what the
first and second prisoners said.
I
etc.
This can be generalized to when there are k colors instead of just
two.
The Three Prisoners
The Three Prisoners
I
Three prisoners are given, uniformly at random, an orange or green
hat. They see the hats of the other people, but not their own.
The Three Prisoners
I
Three prisoners are given, uniformly at random, an orange or green
hat. They see the hats of the other people, but not their own.
I
Later, in separate rooms, each must decide whether to guess his or
her own hat color, or to pass.
The Three Prisoners
I
Three prisoners are given, uniformly at random, an orange or green
hat. They see the hats of the other people, but not their own.
I
Later, in separate rooms, each must decide whether to guess his or
her own hat color, or to pass.
I
If everyone who guesses is correct, then everyone is set free. If one
person guesses wrong, or if they all pass, they are all subjected to
M. Night Shyamalan’s “The Last Airbender”.
The Three Prisoners
I
Three prisoners are given, uniformly at random, an orange or green
hat. They see the hats of the other people, but not their own.
I
Later, in separate rooms, each must decide whether to guess his or
her own hat color, or to pass.
I
If everyone who guesses is correct, then everyone is set free. If one
person guesses wrong, or if they all pass, they are all subjected to
M. Night Shyamalan’s “The Last Airbender”.
If they use the optimum strategy, how likely is it they will all be freed?
The Three Prisoners
I
Three prisoners are given, uniformly at random, an orange or green
hat. They see the hats of the other people, but not their own.
I
Later, in separate rooms, each must decide whether to guess his or
her own hat color, or to pass.
I
If everyone who guesses is correct, then everyone is set free. If one
person guesses wrong, or if they all pass, they are all subjected to
M. Night Shyamalan’s “The Last Airbender”.
If they use the optimum strategy, how likely is it they will all be freed?
Surely, it can’t be more than 50% ... right?
Now for something with less mathematics ...
A man is locked in room in the middle of a desert, with a town on the
edge of a desert. The only object in the room is a table. He frees himself
from the room and gets to the town without walking there. How?
Now for something with less mathematics ...
A man is locked in room in the middle of a desert, with a town on the
edge of a desert. The only object in the room is a table. He frees himself
from the room and gets to the town without walking there. How?
Now for something with less mathematics ...
A man is locked in room in the middle of a desert, with a town on the
edge of a desert. The only object in the room is a table. He frees himself
from the room and gets to the town without walking there. How?
Now for something with less mathematics ...
A man is locked in room in the middle of a desert, with a town on the
edge of a desert. The only object in the room is a table. He frees himself
from the room and gets to the town without walking there. How?
Now for something with less mathematics ...
A man is locked in room in the middle of a desert, with a town on the
edge of a desert. The only object in the room is a table. He frees himself
from the room and gets to the town without walking there. How?
Now for something with less mathematics ...
A man is locked in room in the middle of a desert, with a town on the
edge of a desert. The only object in the room is a table. He frees himself
from the room and gets to the town without walking there. How?
The Three Prisoners
I
Three prisoners are given, uniformly at random, an orange or green
hat. They see the hats of the other people, but not their own.
I
Later, in separate rooms, each must decide whether to guess his or
her own hat color, or to pass.
I
If everyone who guesses is correct, they win. If one person guesses
wrong, or if they all pass, they lose.
If they use the optimum strategy, how likely is it they will all be freed?
Three Prisoners Solution
Surprisingly, the prisoners can win 75 % of the time.
Three Prisoners Solution
Surprisingly, the prisoners can win 75 % of the time.
I
Each player follows the strategy that if he or she sees both the
other hats are the same color, he or she will guess the
opposite color. Otherwise pass.
Three Prisoners Solution
Surprisingly, the prisoners can win 75 % of the time.
I
Each player follows the strategy that if he or she sees both the
other hats are the same color, he or she will guess the
opposite color. Otherwise pass.
I
If they are given GGG or OOO, then all three prisoners guess
wrong. If they are given GGO, GOG , OGG , OOG , OGO, or
GOO, exactly one prisoner will guess, and will be correct.
Three Prisoners Solution
Surprisingly, the prisoners can win 75 % of the time.
I
Each player follows the strategy that if he or she sees both the
other hats are the same color, he or she will guess the
opposite color. Otherwise pass.
I
If they are given GGG or OOO, then all three prisoners guess
wrong. If they are given GGO, GOG , OGG , OOG , OGO, or
GOO, exactly one prisoner will guess, and will be correct.
Three Prisoners Generalized
I
Suppose now there are 2m − 1 prisoners (again, each getting one of
two colors). Then the prisoners can win with probability 1 − 1/2m
using hamming codes from coding theory.
Three Prisoners Generalized
I
Suppose now there are 2m − 1 prisoners (again, each getting one of
two colors). Then the prisoners can win with probability 1 − 1/2m
using hamming codes from coding theory.
I
A Hamming code H ⊆ {0, 1}2
m
−1
has the following properties.
Three Prisoners Generalized
I
Suppose now there are 2m − 1 prisoners (again, each getting one of
two colors). Then the prisoners can win with probability 1 − 1/2m
using hamming codes from coding theory.
I
A Hamming code H ⊆ {0, 1}2 −1 has the following properties.
|H|
I |H| is fairly small:
= 1/2m .
|{0, 1}2m −1 |
I H meets the Hamming bound, which for our purposes means
m
every element of {0, 1}2 −1 is either in H, or there is a unique
single bit such that, if flipped, will yield a binary string in H.
I Such an H exists.
m
Three Prisoners Generalized
I
Suppose now there are 2m − 1 prisoners (again, each getting one of
two colors). Then the prisoners can win with probability 1 − 1/2m
using hamming codes from coding theory.
I
A Hamming code H ⊆ {0, 1}2 −1 has the following properties.
|H|
I |H| is fairly small:
= 1/2m .
|{0, 1}2m −1 |
I H meets the Hamming bound, which for our purposes means
m
every element of {0, 1}2 −1 is either in H, or there is a unique
single bit such that, if flipped, will yield a binary string in H.
I Such an H exists.
I
Strategy for 2m − 1 prisoners.
m
Three Prisoners Generalized
I
Suppose now there are 2m − 1 prisoners (again, each getting one of
two colors). Then the prisoners can win with probability 1 − 1/2m
using hamming codes from coding theory.
I
A Hamming code H ⊆ {0, 1}2 −1 has the following properties.
|H|
I |H| is fairly small:
= 1/2m .
|{0, 1}2m −1 |
I H meets the Hamming bound, which for our purposes means
m
every element of {0, 1}2 −1 is either in H, or there is a unique
single bit such that, if flipped, will yield a binary string in H.
I Such an H exists.
I
Strategy for 2m − 1 prisoners.
I Each prisoner considers the hat colors as a binary string of
length 2m − 1, with one spot unknown.
I If that spot can be filled in so that the resulting string forms a
codeword, guess the opposite value. Otherwise pass.
I One person guesses correctly if the binary string is not a
codeword. If it is a codeword, then they all guess wrong.
I The probability the string is not a codeword is 1 − 1/2m .
m
The Light Bulb
I
In the prison, there is a room with nothing but a light bulb
and a switch.
The Light Bulb
I
In the prison, there is a room with nothing but a light bulb
and a switch.
I
Each day, uniformly at random, the warden selects one of the
100 prisoners to put in the room.
The Light Bulb
I
In the prison, there is a room with nothing but a light bulb
and a switch.
I
Each day, uniformly at random, the warden selects one of the
100 prisoners to put in the room.
I
At any point, any prisoner can declare he or she thinks
everyone has entered the room at least one. If that prisoner is
correct, they are all freed. If not, well, you know ...
The Light Bulb
I
In the prison, there is a room with nothing but a light bulb
and a switch.
I
Each day, uniformly at random, the warden selects one of the
100 prisoners to put in the room.
I
At any point, any prisoner can declare he or she thinks
everyone has entered the room at least one. If that prisoner is
correct, they are all freed. If not, well, you know ...
Can the prisoners devise a strategy to guarantee their freedom?
Wait and guess
I
The expected time it takes for all the prisoners to visit the
room at least once is identical to the “Coupon Collect
problem”. On average, it will take roughly n ln n days for the
case with n prisoners. If n = 100, this is rougly 460 days.
Wait and guess
I
The expected time it takes for all the prisoners to visit the
room at least once is identical to the “Coupon Collect
problem”. On average, it will take roughly n ln n days for the
case with n prisoners. If n = 100, this is rougly 460 days.
I
If they were to wait ten years, they would be at most a 10−14
chance that not everyone had visited.
The Light Bulb
I
In the prison, there is a room with nothing but a light bulb
and a switch.
I
Each day, uniformly at random, the warden selects one of the
100 prisoners to put in the room.
I
At any point, any prisoner can declare he or she thinks
everyone has entered the room at least one. If that prisoner is
correct, they win. Otherwise they lose.
Can the prisoners devise a strategy to guarantee their freedom?
“I’m feeling lucky” solution
I
Break future days into 100 day blocks, specified ahead of time.
“I’m feeling lucky” solution
I
Break future days into 100 day blocks, specified ahead of time.
I
On day 1 of the block, turn the light on.
“I’m feeling lucky” solution
I
Break future days into 100 day blocks, specified ahead of time.
I
On day 1 of the block, turn the light on.
I
If a prisoner visits the room twice in the hundred days, he or
she turns the light off.
“I’m feeling lucky” solution
I
Break future days into 100 day blocks, specified ahead of time.
I
On day 1 of the block, turn the light on.
I
If a prisoner visits the room twice in the hundred days, he or
she turns the light off.
I
Otherwise, a prisoner does nothing.
“I’m feeling lucky” solution
I
Break future days into 100 day blocks, specified ahead of time.
I
On day 1 of the block, turn the light on.
I
If a prisoner visits the room twice in the hundred days, he or
she turns the light off.
I
Otherwise, a prisoner does nothing.
I
If, at the end of a 100 day block the light is still on, then all
the prisoners visited during that block.
“I’m feeling lucky” solution
I
Break future days into 100 day blocks, specified ahead of time.
I
On day 1 of the block, turn the light on.
I
If a prisoner visits the room twice in the hundred days, he or
she turns the light off.
I
Otherwise, a prisoner does nothing.
I
If, at the end of a 100 day block the light is still on, then all
the prisoners visited during that block.
Unfortunately, the expected running time is longer than 1040 years
...
Single Counter Solution
I
Designate one prisoner to be the “counter”, who keeps a
count that starts at 1.
Single Counter Solution
I
Designate one prisoner to be the “counter”, who keeps a
count that starts at 1.
I
Counter: when she is in the room, she makes sure the light is
off. Everytime she turns the light off, she adds one to her
count.
Single Counter Solution
I
Designate one prisoner to be the “counter”, who keeps a
count that starts at 1.
I
Counter: when she is in the room, she makes sure the light is
off. Everytime she turns the light off, she adds one to her
count.
I
Every other prisoner: the first time they enter the room with
the light off, turn it on. Otherwise do nothing.
Single Counter Solution
I
Designate one prisoner to be the “counter”, who keeps a
count that starts at 1.
I
Counter: when she is in the room, she makes sure the light is
off. Everytime she turns the light off, she adds one to her
count.
I
Every other prisoner: the first time they enter the room with
the light off, turn it on. Otherwise do nothing.
I
Once the counter’s count reaches 100, then the counter
knows everyone has entered the room.
Single Counter Solution
I
Designate one prisoner to be the “counter”, who keeps a
count that starts at 1.
I
Counter: when she is in the room, she makes sure the light is
off. Everytime she turns the light off, she adds one to her
count.
I
Every other prisoner: the first time they enter the room with
the light off, turn it on. Otherwise do nothing.
I
Once the counter’s count reaches 100, then the counter
knows everyone has entered the room.
Expected running time: roughly 28.5 years.
100 Boxes
Another 100 prisoners are subjected to the following game:
100 Boxes
Another 100 prisoners are subjected to the following game:
I
A room of the prison has 100 boxes, and each contains the
name of a different prisoner.
100 Boxes
Another 100 prisoners are subjected to the following game:
I
I
A room of the prison has 100 boxes, and each contains the
name of a different prisoner.
Each prisoner enters the room at some point, and sequentially
opens 50 boxes hoping to find his or her name.
100 Boxes
Another 100 prisoners are subjected to the following game:
I
I
I
A room of the prison has 100 boxes, and each contains the
name of a different prisoner.
Each prisoner enters the room at some point, and sequentially
opens 50 boxes hoping to find his or her name.
If every prisoner finds his or her name, they win. If one person
fails to find their name, they all lose.
100 Boxes
Another 100 prisoners are subjected to the following game:
I
I
I
A room of the prison has 100 boxes, and each contains the
name of a different prisoner.
Each prisoner enters the room at some point, and sequentially
opens 50 boxes hoping to find his or her name.
If every prisoner finds his or her name, they win. If one person
fails to find their name, they all lose.
It seems like there is only a 25% chance the first two prisoners will
both find their names. However, there is a strategy so that every
prisoner finds his or her name with probability greater than 30%!
Can you find it?
Thanks!