IdealogianMy Brain Squished Into A Web Page |
|
January 6, 2004Brain TeaserHere's my favorite brain teaser. The setup is somewhat elaborate, but the payoff is worth it. Attempted solutions or requests for clarification are welcome in the comments section. Twenty inmates are scheduled for execution in the morning. The night before their execution, the executioner notifies them that the manner of their execution will be as follows, giving them a chance to gain their freedom. (Don't ask why - it's a brain teaser!) The prisoners will be lined up in random order, single file, such that the last person on line can see all those in front of him but none of those behind him, the second to last can see the eighteen in front of him but not the one behind him, and so on. The executioner will then place on each of their heads a small hat - either black or white, with any possible ratio of black to white hats among the twenty of them (e.g., they could all be black, they could all be white, there could be fifteen black and five white, etc.). The executioner will start from the end of the line (with the prisoner who can see all those in front of him). One by one, making his way towards the front of the line, he will ask each prisoner, "What is the color of the hat on your head?" If the prisoner answers correctly, he will be freed immediately; incorrectly, he will be shot immediately. Prisoners are not allowed to turn their heads or try any "funny stuff" to communicate with each other. This includes answering "Black, er, I mean White," conspicuously coughing, or even answering the question in an odd tone of voice. The prisoners get together that night and realized that, if they play their cards right and cooperate, they can guarantee that a certain number of them will make it out alive. (This does not include any possibility that some may get it right by chance.) What is the greatest number that they can definitely save, and how do they do it? If you've heard it before, please don't post the answer (even just the number - that's part of the puzzle). If you think you've figured it out now, please do! Warning: The comments now contain the correct answer (and a few interesting not-as-correct ones). Posted January 6, 2004 9:50 AMComments
first I thought 10 with the rest having 50% shot. i.e. every even one (20, 18) says the color of the guy in front of him. therefore 50% of them have 100% shot, and 50% have a 50% shot. then in thinking even and odds. I thought, wait a second. how can one convey information to all of them. since there are an odd amount left, there are going to be an odd number of one color hat. just announce the color that's odd. Therefore, every other person can figure out based on the calls what color they are. i.e. person 19 knows what's odd. he counts each color and is able to determine what color he is. so on and so forth. Posted by: Shaya at January 6, 2004 11:19 PMVery good. When I was first told the riddle, I was actually given an incorrect "best answer." You can save 16 if the last (in line; first to be asked) four use themselves as bits (and "black" and "white" as "0" and "1") to indicate the number of white hats in the remaining 16. (2^4 = 16) I later found your answer, which is obviously better (and simpler as well). I've also heard some very complex ways to save 13, but I won't bother detailing them here. Posted by: Reuven at January 7, 2004 9:04 AMIt seems Shaya's answer is easy to understand if you already know it, and not so easy to understand if you don't. So I'll explain. (Only read further if you really want the answer given to you on a silver platter.) Though there are a couple of very minor variations on the correct answer, I'll explain it the way Shaya stated it. Other than the last guy in line (the first to be asked, a.k.a., "the martyr"), there are 19 hats. Since 19 is an odd number, any way of dividing that in two will result in 1 even number and 1 odd number (e.g., 4 and 15, 10 and 9, even 0 and 19, if we consider 0 to be even, which we will). This means that one color will be present in an even number and one will be present in an odd number. The martyr (who actually has a 50% chance of survival) simply announces the color of which he sees an odd number. How does that help? After the martyr, the executioner moves on to the second to last guy, #19. He has just been told, for example, that there are an odd number of black hats among the remaing 19 of them. Looking at the 18 in front of him, he himself sees either an even or odd number of black hats. This shows that any one man, knowing what the martyr told them about which color is present in an odd number, and knowing the colors of the 18 hats that aren't his, can determine the color of his own hat. #19 can see all the hats in front of him and thus determines the color of his own hat. #18 can see only 17 of the other hats, but he has heard what #19 just said, and thus also knows the colors of the 18 hats that aren't his. #17 sees only 16 hats in front of him, but heard #19's and #18's responses. And so on. Posted by: Reuven at January 7, 2004 1:48 PMSo if the 19th guy sees 8 b and 8 w in front of him, what does he yell out? Posted by: Devon at January 23, 2004 5:35 PMDepends on what the 20th guy had said. If 20 had said "black," then 19 knows there can't possibly be a total of 8 black hats on the first 19 (himself included). Since he sees only 8, his must be black to bring the total to 9 - an odd number. And vice versa if 20 had said "white" - 19 would need to be white to bring the total number of white hats (in the first 19) to the odd 9. Posted by: Reuven at January 26, 2004 3:03 PMSo I missed the 20 prisoners. In this case, yes there is always an odd number ahead of him. However this problem should be solveable for n+1; n = 1,2,3... prisoners so in the case of odd prisoners in line, calling out the odd prisoners will not work. Posted by: devon at January 26, 2004 4:16 PMWith a bit of a twist, you can get it working for an odd number also. Let's assume there are 19 prisoners. 19 looks at 1-17 (i.e., starts off ignoring 18) and notes which color has the odd number. However, before announcing that color, he looks at the hat on 18. If 18 has a black hat, 19 announces the odd color as he normally would. However, if 18 has a white hat, 19 announces the opposite - i.e., the color that has an even number among 1-17. Now, 18 hears what 19 just said and sees the hats of 1-17. If 19 announced the odd color, 18 knows he is black. If 19 announced the even color, 18 knows he is white. Thus, 18 can save himself. Now, 1-17 have just heard what 19 and 18 said. If 18 said he was black, they know the color that 19 announced was the odd color. If 18 said he was white, they know the color that 19 didn't announce was the odd color. Thus, 1-17 can proceed as they would have in the version above (i.e., as 1-19 proceeded when there were 20 people total). Posted by: Reuven at January 26, 2004 4:32 PMthis problem is in fact solveable for any number of prisoners (odd or even) and any number of colors (not just black and white, can even be 10,000 colors, as long as these colors are known beforehand) To simplify, suppose there are 6 people and 50 hat colors. We'll assign a value between 0 and 49 to each of the hat colors. Now suppose the hat assignments look like this: 36 43 7 19 8 1 The guy at the back adds up all the hats in front of him mod 50. So he'd get (43 + 7 + 19 + 8 + 1) mod 50 = 28. Now the second last guy subtracts all the hats in front of him from that number and that is his answer. So (28 - 7 - 19 - 8 - 1) mod 50 = 43. The next guy keeps track of the running total and the last value (28 - 43) mod 50 = 35 and then subtracts all the hats in front of him from this number: (35 - 19 - 8 - 1) mod 50 = 7. The next guy does the same thing: (35 - 7) mod 50 = 28, and (28 - 8 - 1) mod 50 = 19. And so on…. This can be easily generalized to n people with k hat colors, in which case (n-1) prisoners are guaranteed release, while the last prisoner has a 1/k chance of surviving Posted by: vvilly at January 29, 2004 4:04 PMAn explanation of vvilly's clever answer has been posted here. Posted by: Reuven at February 1, 2004 12:51 AMPost a comment
|
About MeArchives
February 2005
January 2005 December 2004 November 2004 October 2004 September 2004 August 2004 July 2004 June 2004 May 2004 April 2004 March 2004 February 2004 January 2004 December 2003 November 2003 October 2003 September 2003 August 2003 SearchLinksTech Stuff |