Originally posted by: DaShen
Originally posted by: CarpeDeo
And this one is #7 from above, but I'm putting it again here for all to see.
Gargomoyle (sp?) has captured 50 smurfs. He tells them, "Tomorrow is your execution day. But I will give you a chance to live. I will line you up, all facing the same direction. I will randomly put either a black or white hat on your head. Starting from the smurf in the back (the one who can see the other 49 in front), if you guess the correct color of your hat, I will let you go." The smurfs have one night to figure out a plan. What plan do they come up to save the most # of smurfs? (Note: a smurf can see all the other smurfs in front of him. The 50 hats are randomly distributed (can be 25 white - 25 black or 3 white - 47 black).
This is just a guess. Since I was C.S. we talked a lot about these kinds of problems in Automata Theory.
I figure that you can treat the two colors as a binary pattern. In that case 1 would be white, 0 black.
if the first two smurfs are solids, either 1-1 or 0-0, then the 3rd smurf should guess 1 for 1-1 or 0 for 0-0 in front of him. If the first 2 smurfs are 0-1 or 1-0, then the 3rd smurf should remain silent and the 4th smurf should guess 0 for 0-1 or 1 for 1-0. Iterate through the 50 till you finish guessing.
In this way, worst case scenario (the guesser is wrong every time), only a little more than 66% will be able to leave free, since 1 out of 4 will make an absolute guess, and 1 out of the first 3 will have to remain in the next guess. (It is more than 25 free with this solution BTW). If only 1/2 of the guessers get it right, which follows probability, then more like 90% go free.
I am pretty sure this is a good way of doing it, but there could be a better one. You could even write a pice of code with random generated binary to check this solution.
There is one other solution that at best can save all 50 of the Smurfs but it assumes two things. 1) The smurf in front will always know who is right behind them. Another way of saying this is that when one person is taken off the line the line will compact so that there is no space. 2) There is a time delay between saying your color and remaining silent before the one in front can say anything.
*You can eliminate the first one by having a global clock that all of the smurfs can see, and having each smurf at the assigned seat, have a designated time. In other words, if you start at the beginning of the hour then the nth, or 50th, person has one minute to respond.
Here is the other solution I thought of, this is probably the one that CarpeDeo was thinking of, but its worst case is not 49. In most cases it is, but it can be much worse.
Think of 2 things that must be satisfied.
1. You wish to save yourself
2. You wish to save the people in front of you, but you cannot say anything but your own color if you wish to satisfy postulate 1.
So if the last person in line guesses the n-1 color, in this case the 49th person, the nth person will have a 50% chance of surviving.
Because of these two postulates, the factor of time becomes very necessary. Therefore two rules must be given.
If you know your color, and by default since the n-1 color is broadcasted to everyone by the last, or nth person, then you must do one of two things.
If the person in fron of you n-2 is your color, you guess your color, otherwise you remain silent.
Your silence, if on a time delay everyone agrees upon, will broadcast to the person in front of you that they are the opposite color.
In either case the person directly in front of you, as well as all the other smurfs will, knows this smurfs color, and therefore can do the algorithm again to the next person in line.
Whoever is the constant color in the back is the key to the whole thing working. In this case whoever is in the 49th position.
----------------------
The problem is that if the people are given alternate colors for a while, the "time delay" becomes more important. Because with the time delay, any person that is silent after the last person who guessed will switch the color down to you. i.e. - if the 49th person is silent and the 50th color called black, then the 48th person is white, and so on. With the time delay, either by everyone trying to keep synchronized or a global clock, and some good logging, everyone after the 50th person will know what color he is.
Example with 5 smurfs.
white11010
silence1010
1silence010
10silence10
They all "guess" correctly. And the 5th one was lucky.
Now with good logging the 1st one in line will know he is black. Basically all of them know there color.
-----------------------
Without the clock and without the compacting of the chairs, the solution becomes much more complicated. The smurf must count how many broadcasts have been made behind him because he can never be sure as to who is behind him. If he is the n-m person, then he must wait for at least m-1 people to "guess". If m-1 people guess, then the last persons guess is the opposite of what your color is. If m people guess, then the last persons guess is the same as your color. The only problem remains if the people alternate through most of the list to the point where it is humanly, or smurfly impossible , to keep track of the time delay. There is a chance that one person in the middle must take a guess, so that the rest can survive.
white 110110101010...
silence 10110101010...
1silence 0110101010...
10white 110101010...
10silence 10101010...
silence
.
.
.
The front people don't know what color they are. The last one to figure out his color from whoever was behind him must restart the guess (and he might have to sacrifice himself). Then he restarts the cycle from him and all people who know behind him can sit back and relax and guess when the cycle is over. So there is a slim chance that less than 49 people will survive.
I think this is a solution (I figured it out on the Metro back home), that works in most case giving 49-50 smurfs surviving, but without the assumptions it could be less.