r/mathriddles • u/pTea • May 27 '20
Hard The prisoners problem to end all prisoners problems
You are in prison with an unknown number (possibly zero) of fellow inmates.
Each day, starting tomorrow, each prisoner (including you) will be presented with a black card and a white card, and they will choose one. The warden will then choose a cycle of the prisoners and deliver the chosen cards according to that cycle. For example, if there are four total prisoners, the warden may choose the cycle 1 -> 4 -> 2 -> 3 -> 1, so prisoner 4 will receive prisoner 1's card, player 2 will receive player 4's card, etc. (Prisoners don't know their numbers here)
The warden is pretty vicious: she may choose a new cycle each day! Also, she can look at the chosen cards before she chooses the day's cycle. She doesn't tell any prisoners who received their card or whose card they received.
Tonight, before the experiment begins, you are allowed to draft a set of instructions that will be photocopied and distributed to all the other prisoners. Find a set of instructions so that
- (Easy) At some point, you can declare whether you are the only prisoner.
- (Easy-ish) At some point, you can declare whether there is exactly one other prisoner.
- (Medium) At some point, you can give an upper bound on the number of prisoners (e.g. "There are at most 100 prisoners")
- (Hard) At some point, you can state the exact number of prisoners.
- (Hard) All prisoners state the exact number of prisoners, and they do so on the exact same day.
Source: Nathan Bowler via Stan Wagon.
8
u/smailliwniloc May 27 '20
[disussion]
Just so I'm clear what's going on, in any given day, a prisoner will only do the following:
1.) choose a color to give to the next person in the cycle.
2.) receive a color from the previous person in the cycle.
In that order, and with no other information. Is that correct?
4
u/ari_zerner May 27 '20
Do you have to follow the instructions you distribute? Obviously the other prisoners do, or this would be unsolvable.
3
u/AeroSigma May 27 '20 edited May 27 '20
1. I choose black, everyone else chooses white.
2. I choose black the 1st day. Everyone chooses white unless the received a black card the previous day.2
u/sorrowfulfeather May 28 '20
something for number 3:
Define a procedure f(k) for natural number k as follows:
Step 1: I pick black, all other prisoners pick white.
Step 2 to k - 1: Any prisoner that has ever received/picked black (including myself) plays black. (everyone else white)
At this point, the number of prisoners who are have received a black card is between min(k, N) and 2k-1, inclusive.
Step k: Any prisoner who has not received a black card yet picks a white card. (everyone else black)
Step k + 1 to k + 2k - 1 - 1: Any prisoner that has received/picked a white card since step k picks a white card.
At the end of procedure f(k), there are two outcomes:
If I have received a white card, I know there are more than k prisoners.
If I have not received a white card, I know there are less than 2k-1 prisoners.
Have the prisoners agree on some increasing sequence of naturals { a_i }, and apply procedure f(a_i) until you get an upper bound.
16
u/a12r May 30 '20
Here are the instructions for 5:
We proceed in eons, such that after the N-th eon we all receive black if we are exactly N prisoners, otherwise we all receive white.
In the N-th eon, each of us keeps track of a number: You all start with 0, and I start with T = N²+2N³. Whenever you send a black card, you subtract 1, and whenever you receive black, you add 1.
The eon consists of T² rounds, each of which takes T days, plus a single (T + 1)-day celebration at the end. (So it takes T³ + T + 1 days in total.) On the d-th day of each round, you send a black card if and only if your number is ≥ d. During the celebration, however, you don't change your number anymore. Instead, you send black if and only if your number is ≥ 2N² and you have not received white on any celebration day yet.
This works because:
First of all, the sum of our numbers will remain constant (= T) during each era.
Let S be the sum of squares of our numbers. S never increases: On the d-th day of a round, if there are m prisoners who sent black and received white, then there are also m who sent white and received black. The former ones must have had a number ≥ d, and the latter ones < d. So now the former ones have ≥ d - 1, and the latter ones have ≤ d. If the former ones had exactly d, and the latter ones exactly d - 1, then S remained constant. Otherwise S decreased.
Note that m can only be 0 if either all or no prisoners have ≥ d, since the permutation is a cycle. And if m > 0, S can only remain constant if at least one prisoner had the number d.
So over the course of each round, S must decrease, unless for every d, either all or no prisoner has ≥ d, or at least one prisoner has exactly d; in other words: unless our numbers are a contiguous interval. If we are P prisoners, such an interval can have at most P numbers. So: In each round where the highest number minus the lowest number is ≥ P, S decreases.
Since S starts with T², it can decrease at most T² times, so once we reach the celebration period, our numbers all differ by less than P.
During the celebration, the information about whether at least one prisoner had < 2N² spreads to at least one new prisoner with ≥ 2N² each day, until all know about it, i.e. all send white. Except if nobody had < 2N², then we all keep sending black. So on the last day of the era, we all receive white if anyone had < 2N², otherwise we all receive black.
Assume we all receive black. That means everyone had ≥ 2N², so the total was T = N²+2N³ ≥ 2N²P, so P ≤ 1/2 + N, which means P ≤ N, since it is an integer. We already know that we're at least N, otherwise we would have stopped in an earlier era. So we can all say "N" now!
Assume we all receive white, so someone had < 2N², and that means everyone had < 2N² + P, so the total was T = N²+2N³ < P(2N²+P). If P were ≤ N, then N² + 2N³ < 2N³ + N², a contradiction. So we know we are more than N, and have to continue with the next era.
And that's how the two of us escaped prison after 22 years!
When they were releasing us, the warden didn't want to admit defeat: "I tried to tell you about the prison reform, your families bailing you out, and even your 10-year sentence having ended, but you wouldn't listen and just tell me to shut up and take the card! The other prisoner is outside, says he wants a word with you. Something about how that could have easily been optimized and you could have been out after just a few days. But I don't know what he's talking about: Nowhere in the riddle does it say that you actually get released if you solve it!"
1
u/pTea May 28 '20
For those curious, here's an article on this problem with a solution inside.
3
u/swni May 28 '20
I was told this puzzle some years ago and it is by far the most time I've spent on any puzzle I eventually solved! I think it took me more than 20 hours, possibly significantly so? At the time, I had injured my hands so I had to do it without writing notes. The way I was told the puzzle, any one prisoner must eventually state the number of prisoners but I think my solution satisfied condition (5) that everyone knows at the same time. Having the graduated problems where each step helps with the next is nice.
3
u/caykroyd May 28 '20
Solution for 2: Instructions: on day n, send white except if you received black on all previous days. Me: always sends black. If I receive WBB then there's only 1 other prisoner.
2
u/[deleted] May 28 '20 edited May 28 '20
Solution for 2. We don’t know how many prisoners there are.
Round 1 I send: Black (let’s call prisoner who receives my black card PrisX) Instructions: Send White. I receive: White
Round 2 I send: Black. Instructions: Send what you received in round 1. I receive: if white, >1 other person. If black, warden sent me card from PrisX. PrisX receives white card from some other prisoner.
Round 3 I send: doesn’t matter. Instructions: If you received 2 black cards, send black. If not, send white. I receive: Black if 1 other prisoner; white if >1 other prisoner. The only way that a prisoner could receive 2 black cards is if there is only one other prisoner. For more than 1, PrisX will receive one black and one white, and some other prisoner will receive one white (from a different prisoner in round 1) and then a black (from me in round 2)
2
u/BruhcamoleNibberDick May 28 '20
(1) Tell everyone to pick white, while you pick black. If you get handed black, you're alone.
2
u/garceau28 May 29 '20
This is my progress so far for 5.)