Prisoner hat and light riddles?

Riddle 1:
A prison has 1000 inmates and a room with a light switch, initially off. Every day, a random prisoner is let into the room, and they may flip the switch if they wish. Once a prisoner believes every prisoner has been in the room, he may tell the warden. If he's right, all the inmates are let go, but if he's wrong, they're all killed. The prisoners are allowed to decide on a strategy before any of them are put into the room. How can they all survive?

(Assume the random prisoner choice never "gets stuck", that the prisoners live forever, that they all want out alive, etc.)


Riddle 2:
A prison has infinitely many inmates, one for each integer, and they're numbered. The warden is insane. One night, she decides the next day she'll line up all the inmates and randomly give them either a red or a blue hat. They won't be able to look at their hat or tell others about their hat, but each prisoner can instantly see every other prisoner's hat color. They will be taken in order into a secluded room, asked the color of their hat, and put back in line. The other prisoners are unable to hear their response. After every prisoner has had their turn, all those who answered wrong are killed, and the rest are set free.

The janitor overhears her plans and lets the prisoners know beforehand. They meet and decide on a strategy where no matter what the warden does, only finitely many of them will die. What is their strategy?


I have a solution to (1) and two solutions to (2), but more would be welcome, and at any rate I found these to be interesting so I thought I'd try sharing them.

2013-08-10T13:53:20Z

@Scythian: that was my solution to (1) as well. I tried improving it for a while with multiple "collectors" but got nowhere, though I'm almost sure much better solutions exist.

2013-08-11T13:06:27Z

@Michael/jibz: Excellent idea to keep track of the number of days. I had neglected that information. I'll think about it more now.

@Michael: Riddle (2) has an actual, non-trick, non-wordplay, etc. answer. Actually, at least two; one of mine uses your observation (and more, of course).

2013-08-11T19:03:58Z

@Scythian: Extended. Assuming god-like powers of observation, memory, and reasoning for the inmates is fine. You can phrase the question purely in terms of sets but it's not as interesting or memorable :)

2013-08-13T12:04:46Z

@jibz: For Riddle 1, the prisoners aren't allowed to "call out" numbers, though otherwise I like that solution quite a bit. ("The other prisoners are unable to hear their response.")

@Brian: I didn't link to that Wikipedia page originally since I was hoping not to "taint" people's solutions. Still, I suppose Riddle 2 hadn't had any progress for a few days. For what it's worth, my own solution was different; I heard Wikipedia's solution from the person who first asked me the riddle.

@Scythian: The axiom of choice is accepted by almost all modern mathematicians. Existence of choice functions isn't terribly controversial, though in some sense it is speculation about the nature of infinity. I have ideas for ensuring at least one inmate lives in the finite version; I don't believe "a solution exists only if there's an infinity of inmates".

@Michael: I had thought of similar strategies, but how can you be sure it

2013-08-13T15:11:50Z

@Michael: (second try) I had thought of similar strategies, but how can you be sure it terminates? What if the warden never picks the super tracker during phase 3? I had interpreted the riddle as requiring a strategy where the prisoners are guaranteed to get out, not just get out with "high probability" in some sense.

Scythian19502013-08-10T09:41:51Z

Favorite Answer

Riddle 1: I think there's probably more than one way to do this, the question is, which strategy is likely to free the inmates the soonest? A safe but lengthy strategy would be to pick a guy whose job is to keep track, and to make the announcement, as follows:

Tracker: If he sees the light OFF, he leaves it alone. If he sees it ON, he turns it OFF, and adds 1 to his count, which begins at 0. When he reaches a count of 1000, he makes the announcement.

All Others: If any see the light OFF, and have never turned it ON before, they turn it ON. Otherwise, do nothing.

This could take a while before all the inmates gain their freedom. To see how this works, try using 3 or 4 prisoners, not 1000.

Riddle 2: I'll get back to this one later.

Edit: Riddle 2 is really, really difficult. I'd like for you to extend this question, because it seems unlikely that I'll have anything resembling a full solution by tomorrow. What I have right now, work in progress, is for the inmates to first consider all possible sequences of red and blue hats, and then partition them all into sets, each set having a "root" sequence such that all the remaining members of the set differs from the root in only one position. All inmates agree to only assume the root, if they recognize that the actual sequence they see after colors are assigned belong to one particular set. That is, the set that has the sequence they see, which includes their own hat being either red or blue. There's a number of things I need to prove to make this a real solution, I'm not there yet. Of course, I make the assumption that these inmates have God-like powers of being able to not only see an infinite sequence of red and blue hats, but being able to remember an infinity of sets after having constructed them, each having an infinity of member sequences each infinitely long. Otherwise, I do believe that a practical solution that can be done by ordinary people is probably impossible.

Edit 2: Brian, that wiki article about this, clear as mud. What I fear is that "a solution exists only if there's an infinity of inmates", i.e., no improvement over random deaths in the case of a finite number of inmates. In which case, I'll just throw up my hands. It could end up being dependent on assumptions made about infinity, which could very well be arbitrary. That is, to one mathematician, a solution "definitely" exists, to another, "definitely does not" exist, depending on which assumptions they hold to be true about infinity and drawing up sets from it.

As of right now, I can't see a way to improve odds for a finite number of inmates. That is, achieving some kind of an asymptotic less-than-infinite number of inmates killed as the total number increases. Until I am at least able do that, I think I'll pass on this problem. I don't want to get into speculations about the nature of infinity.

Edit 3: Not to be disrespecting mathematicians, just because something is "accepted by almost all modern mathematicians" doesn't make it true. It simply means it's a axiom that's popularly deemed to be valid in order to have some interesting math to go with it. The whole point of an axiom is that what shall be an axiom is a matter of choice (no pun intended here). I don't want to get into things that "only happens at infinity", I prefer things that have at least some practical realization.

?2016-10-02T07:12:35Z

Prisoner Hat Riddle

?2016-06-10T23:04:26Z

1

?2013-08-11T12:13:52Z

@Josh: sorry i missed that detail about prisoners not being able to hear each other.

***************edit 2:
Brian, i was thinking about this riddle riding my bike earlier and I'm amazed at how close i was to the solution. I was actually thinking of equivalence classes of sequences and was gonna suggest that it might need the axiom of choice and something like vitali sets! Then i clicked on your link. Oh well...
Great Riddle btw!

***************edit 1:
Riddle 1:
I don't know how to save all but a finite number of them. The best I can do so far is to save a fraction of the prisoners that can be made to approach 1 arbitrarily fast. The prisoners agree on a strictly (and preferably a very rapidly) increasing sequence (a.n) of natural numbers with a.1 = 1. For each n, they designate the a.n-th prisoner to take one for the team. They agree that red = 1 and blue = 0.¹ When it's the a.n-th prisoner's turn, he calls out the the mod 2 sum S of colors over the block of prisoners (a.n + 1), ...., (a.(n+1)-1).² If he's lucky, his hat is the same color. But meanwhile, each prisoner in that block now knows hisr own color, which equals (S - the sum of all other colors in that block) mod 2. Since the blocks get bigger and bigger, the survival rate tends to 1.
_______________
¹ The scheme generalizes to any number k of colors – just make all calculations mod k.
² The prisoners agree not to extend the blocks to a.(n+1) to spare the poor chap the agony of knowing he'll be shot and the temptation to call out his own color.

****************edit 0:
Riddle 2:
For the first 999 visits the rules are
If it's off and you're a returning visitor, turn it on. Otherwise do nothing.

For the 1000th visitor the rules are
If it's off, go tell the warden everyone's been to the room. Otherwise turn it off and you become the counter. Set the count at 1.

After the 1st 1000 visits the rules are
If you're the counter and the light is on, turn it off and add 1 to the count and if the count is now 1000, go to the warden; otherwise do nothing. If you're not the counter and the light is off, turn it on; otherwise do nothing.

Anonymous2015-08-13T08:47:28Z

This Site Might Help You.

RE:
Prisoner hat and light riddles?
Riddle 1:
A prison has 1000 inmates and a room with a light switch, initially off. Every day, a random prisoner is let into the room, and they may flip the switch if they wish. Once a prisoner believes every prisoner has been in the room, he may tell the warden. If he's right, all the inmates...

Show more answers (4)