You and 99 strangers are kidnapped by aliens. Their plan with you is as follows: they’re going to bury you up to your necks in sand in a single file line and place a skin tight white or black hat on everyone’s head. There are not necessarily 50 white and 50 black hats – the ratio of the 2 is random. The person in the back of the line – person number 100 – can see all 99 hats in front of them, but not the hat on their own head. The person in front of them – person 99 – can see all the 98 hats in front of them and so on until you get to person one, who can’t see anything. Starting from the back, person 100, the aliens will ask each person what color they think they hat on their own head is. If they are right, they can go free. If they are wrong, they are shot and killed. The aliens give everyone ten minutes to strategize before they are buried and the questioning begins. The question is – what strategy can you and the strangers devise to guarantee as many people’s safety as possible, and how many people will this strategy save? The only words you’re allowed to save when it’s your turn are “white” or “black” – nothing more. You cannot change your inflection or volume to communicate additional info. For the purpose of this riddle the only things that can be communicated during the questioning are the word “white” and the word “black” in and of themselves.
The most common strategy people come up with is person 100 to say the color of the hat in front of them, therefore saving person 99 but risking their own life. It then resets at person 98 and so on, so they can guarantee the safety of 50 people. But there is a better strategy. Before you are buried, you assign the word “black” to mean odd and the word “white” to mean even. This code will only apply to what person 100 says. After you’re buried, and when it’s time for person 100 to kick off the questioning, they will count all the white hats in front of them. If it’s an odd number they say “black”, if it’s an even number they say “white”. They may or may not survive because no one can see their hat, but now everyone ahead of them knows whether they saw an odd or even number of white hats. So let’s say person 100 sees 45 white hats and says “black,” which is odd. Then it’s person 99’s turn. If they also count 45 white hats – an odd number – they know that their hat must be black. But if they only count 44, an even number, they know their hat must be white. Every time someone after person 100 declares that their hat is white, everyone in front of them knows whether to check for an odd or even number ahead of them. This strategy, when executed properly, will guarantee the safety of 99 people.