Another hats puzzle

A forum for good logic/math puzzles.

Moderators: jestingrabbit, Moderators General, Prelates

Another hats puzzle

Postby wisnij » Mon Jun 26, 2006 5:24 pm UTC

Twenty prisoners are scheduled for execution, but the sadistic warden has decided they will play a game first. They are to be lined up facing in the same direction, such that each prisoner can only see those other prisoners in front of him. Each of them will be given a hat, which can either be red or blue, chosen randomly. Starting at the back of the line and moving forward, each prisoner will be given a chance to guess the color of his own hat. If he guesses right, he will be pardoned; wrong and he will be shot immediately.

The prisoners are given several minutes to talk with each other ahead of time. After the game starts and the hats are on, any attempt to signal each other or saying anything other than "red" or "blue" will result in them all being shot. What is the optimal strategy for them to follow, i.e. what will guarantee the greatest number of prisoners surviving?


I rather like this one because it's only moderately difficult for someone with a CS or mathematics background, but it's a real stumper for the average layman.
I burn the cheese. It does not burn me.
User avatar
wisnij
 
Posts: 401
Joined: Mon Jun 26, 2006 5:03 pm UTC
Location: a planet called Erp

Postby xkcd » Mon Jun 26, 2006 6:19 pm UTC

I like this puzzle. I first heard it a couple months ago, and I remember sitting for quite a while going, "How about . . . no. Or maybe . . . no," until I finally got it.
User avatar
xkcd
Site Ninja
 
Posts: 365
Joined: Sat Apr 08, 2006 8:03 am UTC

Re: Another hats puzzle

Postby CactusEater » Mon Jun 26, 2006 9:39 pm UTC

wisnij wrote: only moderately difficult for someone with a CS or mathematics background, but it's a real stumper for the average layman.


im boned :(
{o,o}
|)__)
-"-"-
CactusEater
 
Posts: 17
Joined: Fri Jun 23, 2006 10:01 pm UTC

Postby Enzo Dragon » Tue Jul 04, 2006 7:28 am UTC

Sounds to me like the best thing to do would be to name off the hat color in front of you, starting from the guy in the back, until everyone but the guy in the back knows his own hat color for sure.
Enzo Dragon
 
Posts: 4
Joined: Tue Jul 04, 2006 7:16 am UTC
Location: Charon, Pluto's Moon

Postby xkcd » Tue Jul 04, 2006 4:00 pm UTC

Sounds to me like the best thing to do would be to name off the hat color in front of you, starting from the guy in the back, until everyone but the guy in the back knows his own hat color for sure.

No; the only chance you get to say a hat color is when you're asked what color your own is. If you say the color of the guy in front of you, he knows his hat color, but that leaves just a 50% chance that you've said the right color for you.

So yes, you could alternate, every odd-numbered person using his one chance to signal the guy in front of him his hat color, then that even numbered guy saying the color. There, you're guarenteed to save 50 people (more likely 75, but we're looking at worst-case).

But there's a much better solution.
User avatar
xkcd
Site Ninja
 
Posts: 365
Joined: Sat Apr 08, 2006 8:03 am UTC

Postby area » Tue Jul 04, 2006 7:13 pm UTC

Can I post what I think the solution is? I think I save all but one of the prisoners, but I don't want to spoil it for others...
User avatar
area
 
Posts: 9
Joined: Tue Jul 04, 2006 10:49 am UTC

Postby RealGrouchy » Wed Jul 05, 2006 9:19 am UTC

ooh, I'd love to hear it.

It seems I'm only good at these things when I've heard them before. :P
Jack Saladin wrote:etc., lock'd
Mighty Jalapeno wrote:At least he has the decency to REMOVE THE GAP BETWEEN HIS QUOTES....
MYOB/MYOB/MYOB/Canada
User avatar
RealGrouchy
Moderators never lie, so it must be true
 
Posts: 6683
Joined: Thu May 18, 2006 7:17 am UTC
Location: Ottawa, Ontario, Canada

Postby Penguin » Wed Jul 05, 2006 2:58 pm UTC

I'm pretty sure that I heard this on NPR's "Car Talk" a long time ago.

If I recall correctly, (not posting the entire solution so as not to spoil it), it has to do with odd/even numbers, yes?
Penguin
 
Posts: 98
Joined: Wed Jul 05, 2006 2:54 pm UTC
Location: Cambridge, MA

Postby area » Wed Jul 05, 2006 7:24 pm UTC

Penguin wrote:I'm pretty sure that I heard this on NPR's "Car Talk" a long time ago.

If I recall correctly, (not posting the entire solution so as not to spoil it), it has to do with odd/even numbers, yes?


Yeah, that's the solution that I have.
User avatar
area
 
Posts: 9
Joined: Tue Jul 04, 2006 10:49 am UTC

Postby Sitnaltax » Thu Jul 06, 2006 1:31 am UTC

I have a solution that saves 15 in the worst case. I can't see a better way to do it unless you have some underhanded way of conveying more information in the "red" or "blue" statement, which seems against the spirit of the question.

To determine if my solution is the same as yours: In my solution, if there were a 21st person, he would definitely be saved as well. If there are 38, then 32 would be saved.

EDIT: Never mind, the odd/even thing makes sense now.
User avatar
Sitnaltax
 
Posts: 92
Joined: Tue Jul 04, 2006 10:48 pm UTC
Location: Cleveland

Postby RealGrouchy » Thu Jul 06, 2006 8:05 am UTC

It says that the colour of the hats is chosen randomly. Does that mean there are ten of each, or does it mean that there are 0-20 of each colour?
Jack Saladin wrote:etc., lock'd
Mighty Jalapeno wrote:At least he has the decency to REMOVE THE GAP BETWEEN HIS QUOTES....
MYOB/MYOB/MYOB/Canada
User avatar
RealGrouchy
Moderators never lie, so it must be true
 
Posts: 6683
Joined: Thu May 18, 2006 7:17 am UTC
Location: Ottawa, Ontario, Canada

Postby xkcd » Thu Jul 06, 2006 7:04 pm UTC

0-20 of each color. Could be, say, all one or all the other.
User avatar
xkcd
Site Ninja
 
Posts: 365
Joined: Sat Apr 08, 2006 8:03 am UTC

Postby Penguin » Thu Jul 06, 2006 8:09 pm UTC

I don't want to be the irritating n00b who hops around to all the topics in a forum and spoils them for everyone, but I can post a/the solution to this problem if people don't mind.
Penguin
 
Posts: 98
Joined: Wed Jul 05, 2006 2:54 pm UTC
Location: Cambridge, MA

Postby RealGrouchy » Thu Jul 06, 2006 9:46 pm UTC

I say don't (or at the very least, post it in a separate thread clearly marked "ANSWER" or similar), but if you don't mind could you pm it to me?

Cheers

- RG>
Jack Saladin wrote:etc., lock'd
Mighty Jalapeno wrote:At least he has the decency to REMOVE THE GAP BETWEEN HIS QUOTES....
MYOB/MYOB/MYOB/Canada
User avatar
RealGrouchy
Moderators never lie, so it must be true
 
Posts: 6683
Joined: Thu May 18, 2006 7:17 am UTC
Location: Ottawa, Ontario, Canada

Re: Another hats puzzle

Postby sniffels » Fri Jul 07, 2006 8:26 pm UTC

wisnij wrote:They are to be lined up facing in the same direction, such that each prisoner can only see those other prisoners in front of him.


Does this mean that each prisoner can see every person in front of them and their hats? As in, the prisoner in the front of the line cannot see anybody and the second prisoner can see only the first, but the third prisoner can see the first and the second, and the fourth prisoner can see the first, second, and third, and so on?

If so, than I have a working solution. Good puzzle.
sniffels
Has a big nose
 
Posts: 11
Joined: Fri Jul 07, 2006 7:08 pm UTC

Re: Another hats puzzle

Postby area » Sat Jul 08, 2006 8:52 am UTC

sniffels wrote:
wisnij wrote:They are to be lined up facing in the same direction, such that each prisoner can only see those other prisoners in front of him.


Does this mean that each prisoner can see every person in front of them and their hats? As in, the prisoner in the front of the line cannot see anybody and the second prisoner can see only the first, but the third prisoner can see the first and the second, and the fourth prisoner can see the first, second, and third, and so on?

If so, than I have a working solution. Good puzzle.


That's the correct interpretation.
User avatar
area
 
Posts: 9
Joined: Tue Jul 04, 2006 10:49 am UTC

Postby Penguin » Sat Jul 08, 2006 7:31 pm UTC

RealGrouchy wrote:I say don't (or at the very least, post it in a separate thread clearly marked "ANSWER" or similar), but if you don't mind could you pm it to me?


Sure, sorry for the delay with this. I'll try to get to it tonight...
<3!
Penguin
 
Posts: 98
Joined: Wed Jul 05, 2006 2:54 pm UTC
Location: Cambridge, MA

Postby ZombieRoboNinja » Mon Jul 10, 2006 5:40 pm UTC

I've got it figured out for a 50% survival rate off the top of my head... is that the best possible?

EDIT: Nevermind, that solution was already mentioned.
ZombieRoboNinja
 
Posts: 6
Joined: Mon Jul 10, 2006 3:42 pm UTC

Postby Vonkwink » Tue Jul 18, 2006 6:02 pm UTC

Sitnaltax: are you sure that you can definitely save 15 people? I have a solution that saves 13 in the worst case (16.5 expected value. meaning that one person gets partially killed. like a lobotomy or dismemberment or something) - but a slight miscalculation in this would make it seem like you could save 15. I'm wondering if my solution is the best one possible - I can't think of any way of improving it but maybe I am overlooking something.
Vonkwink
 
Posts: 12
Joined: Fri Jul 07, 2006 7:57 am UTC

Postby Oook » Tue Jul 18, 2006 9:38 pm UTC

As as been hinted at, there's a rather neat solution that is certain to save all but one of them.
User avatar
Oook
 
Posts: 13
Joined: Tue Jul 04, 2006 7:30 pm UTC

Postby sniffels » Wed Jul 19, 2006 3:15 pm UTC

Oook wrote:As as been hinted at, there's a rather neat solution that is certain to save all but one of them.


As in 19/20 of the prisoners? That'd be impressive. The best I have right now is 15/20.
sniffels
Has a big nose
 
Posts: 11
Joined: Fri Jul 07, 2006 7:08 pm UTC

Postby Penguin » Wed Jul 19, 2006 3:35 pm UTC

Yes, as in 19/20. That was, at least the last time I checked, twenty minus one.

The best solution has a 50% chance of saving all of them, too. :)
<3!
Penguin
 
Posts: 98
Joined: Wed Jul 05, 2006 2:54 pm UTC
Location: Cambridge, MA

Postby Hawk » Wed Jul 19, 2006 4:42 pm UTC

Are they allowed to say "red" or "blue" more than once during their turn?
Hawk
 
Posts: 4
Joined: Wed Jul 19, 2006 4:41 pm UTC

Postby wisnij » Wed Jul 19, 2006 4:59 pm UTC

The optimal solution is guaranteed to save 19 of them in the worst case, all 20 in the best case. There is a 50% chance of having the best case scenario. One more hint, though it might not help much: there is nothing special about the number 20. The optimal strategy is the same for an arbitratily large number of prisoners.

Hawk wrote:Are they allowed to say "red" or "blue" more than once during their turn?


No.
I burn the cheese. It does not burn me.
User avatar
wisnij
 
Posts: 401
Joined: Mon Jun 26, 2006 5:03 pm UTC
Location: a planet called Erp

Postby Nicolas Bourbaki » Wed Jul 19, 2006 5:10 pm UTC

Here is my solution to the puzzle, which has nothing to do with even or odd numbers.

The last person in line (#N) says the color of the hat in front of them. #N-1 then knows his color. If it is the same as the color in front of him, he says that color at a normal speed. If it is different from the color in front of him, he says it ssslllloooowwwlllyyyy. In general, if person x+1 says their color normally, person x repeats the same color, either normally or slowly depending on if it matches the color in front of them. If person x+1 says their color slowly, person x says the opposite color, again either normally or slowly, depending on the color in front of them.

The warden will just think that about half of the prisoners are idiots!
Nicolas Bourbaki
 
Posts: 18
Joined: Wed Jul 19, 2006 1:08 pm UTC
Location: greenbelt, MD

Postby Spyike Johansson » Wed Jul 19, 2006 5:32 pm UTC

I've got a solution that also saves 19 or 20, but would be pretty obvious to the guard i guess...
Spyike Johansson
 
Posts: 2
Joined: Wed Jul 19, 2006 5:28 pm UTC

Postby wisnij » Wed Jul 19, 2006 5:52 pm UTC

Nicolas Bourbaki wrote:Here is my solution to the puzzle, which has nothing to do with even or odd numbers.


No special communication is allowed. (Maybe they make the prisoners write their answer, and then the guards announce what was written.) The solution does not rely on any tricks of voice, intonation, etc. It is purely a matter of what information each prisoner can determine from what was said by the others.
I burn the cheese. It does not burn me.
User avatar
wisnij
 
Posts: 401
Joined: Mon Jun 26, 2006 5:03 pm UTC
Location: a planet called Erp

Postby sniffels » Wed Jul 19, 2006 6:37 pm UTC

area wrote:
Penguin wrote:I'm pretty sure that I heard this on NPR's "Car Talk" a long time ago.

If I recall correctly, (not posting the entire solution so as not to spoil it), it has to do with odd/even numbers, yes?


Yeah, that's the solution that I have.


Aight, I think I have the 19/20-person answer.
sniffels
Has a big nose
 
Posts: 11
Joined: Fri Jul 07, 2006 7:08 pm UTC

Postby Tropylium » Tue Jul 25, 2006 5:54 pm UTC

I thought a nice all-but-one-saved strategy might be for the last guy to say a code word that tells the colors of all the other guys' hats, before I noticed that saying sumthing else than "red" or "blue" will result in them all beïng shot. Damn. Anyone else fall for this? :?

wisnij wrote:
Nicolas Bourbaki wrote:Here is my solution to the puzzle, which has nothing to do with even or odd numbers.


No special communication is allowed. (Maybe they make the prisoners write their answer, and then the guards announce what was written.) The solution does not rely on any tricks of voice, intonation, etc. It is purely a matter of what information each prisoner can determine from what was said by the others.


I have a tweak for the solution abov: Can the prisoners remain silent for a period before answering? OK, this does end up beïng "communication", but they're not actually doïng anything…

…

No, wait; I think I got the non-comm answer, too.

<checks the solution>

…

Yeppers. Good puzzle. :)
Tropylium
 
Posts: 125
Joined: Tue Jul 25, 2006 9:40 am UTC
Location: Finland

Postby EndofEternity » Sat Sep 02, 2006 5:05 am UTC

i think i got it, checking with the answer thread :D
EndofEternity
 
Posts: 9
Joined: Sat Sep 02, 2006 4:02 am UTC

Postby Mosterencedick9 » Fri Sep 29, 2006 8:47 pm UTC

Spam in the place where I live (ham and pork)
Think about nutrition, wonder what's inside it now (oh boy)
Spam in my luchbox at work (it's the best)
Really makes a darn good sandwich any way you slice it at all
Mosterencedick9
 
Posts: 2
Joined: Fri Sep 29, 2006 10:43 am UTC

Postby Marlayna » Fri Sep 29, 2006 10:05 pm UTC

If it weren't for the spam, I would never have paid attention to this puzzle :lol:

I think I've found the solution. I feel soooo smart. :D
There are 10 kinds of people.
Those who can read binary numbers and those who can't.
Marlayna
 
Posts: 57
Joined: Sun Sep 10, 2006 10:43 am UTC

Postby jwwells » Sat Sep 30, 2006 7:38 am UTC

A hint for the stumped:

Think parity. Think about encoding information about the number of blue hats in front of the first person. And think about how that changes with every correct answer.
jwwells
 
Posts: 149
Joined: Thu Sep 21, 2006 4:47 am UTC


Return to Logic Puzzles

Who is online

Users browsing this forum: No registered users and 2 guests