Below, you will find the lyrics for Can You Solve The Prisoner Hat Riddle? by Alex Gendler.
You and nine other individuals have been captured
By super intelligent alien overlords
The aliens think humans look quite tasty
But their civilization forbids eating highly logical and cooperative beings
Unfortunately, they're not sure whether you qualify
So they decide to give you all a test
Through its universal translator
The alien guarding you tells you the following
You will be placed in a single-file line facing forward in size order
So that each of you can see everyone lined up ahead of you
You will not be able to look behind you or step out of line
Each of you will have either a black or a white hat on your head
Assigned randomly
And I won't tell you how many of each color there are
When I say to begin, each of you must guess the color of your hat
Starting with the person in the back and moving up the line
And don't even try saying words other than black or white
Or signaling some other way, like intonation or volume
You'll all be eaten immediately
If at least nine of you guess correctly, you'll all be spared
You have five minutes to discuss and come up with a plan
And then I'll line you up, assign your hats, and we'll begin
Can you think of a strategy guaranteed to save everyone?
The key is that the person at the back of the line
Who can see everyone else's hats can use the words 'black' or 'white'
To communicate some coded information
So what meaning can be assigned to those words
That will allow everyone else to deduce their hat colours?
It can't be the total number of black or white hats
There are more than two possible values
But what does have two possible values is that number's parity
That is whether it's odd or even
So the solution is to agree that whoever goes first will
For example, say 'black' if he sees an odd number of black hats
And 'white' if he sees an even number of black hats
Let's see how it would play out if the hats were distributed like this
The tallest captive sees three black hats in front of him
So he says 'black'
Telling everyone else he sees an odd number of black hats
He gets his own hat color wrong, but that's okay
Since you're collectively allowed to have one wrong answer
Prisoner two also sees an odd number of black hats
So she knows hers is white, and answers correctly
Prisoner three sees an even number of black hats
So he knows that his must be one of the black hats
The first two prisoners saw
Prisoner four hears that and knows that
She should be looking for an even number of black hats
Since one was behind her
But she only sees one, so she deduces that her hat is also black
Prisoners five through nine
Are each looking for an odd number of black hats
Which they see, so they figure out that their hats are white
Now it all comes down to you at the front of the line
If the ninth prisoner saw an odd number of black hats
That can only mean one thing
You'll find that this strategy
Works for any possible arrangement of the hats
The first prisoner has a 50% chance
Of giving a wrong answer about his own hat
But the parity information he conveys
Allows everyone else to guess theirs with absolute certainty
Each begins by expecting to see an odd or even number of hats
Of the specified color
If what they count doesn't match
That means their own hat is that color
And every time this happens
The next person in line will switch the parity they expect to see
So that's it, you're free to go
It looks like these aliens will have to go hungry
Or find some less logical organisms to abduct