Blog

A Wizard Puzzle

You might have heard of similar puzzles before, such as the ten-hat puzzle. However, I learned of this one from a friend a few years back and found the solution quite interesting. I'm unsure of its actual origin.

There are a hundred wizards, each wearing a black or white hat. They are standing in a line so that each can only see the hats in front of them. Starting from the back, each wizard says anything they want, then guesses the colour of their hat. The twist is that all of the wizards except 2 are evil and will not necessarily follow any strategy, may lie, don't care about the goal, etc. Devise a strategy for the 2 wizards such that at least 1 correct hat is guaranteed.

The solution should work even if an evil god listens to your strategy and arranges the line beforehand to make it fail, or affects the world RNG such that everyone guesses incorrectly. The evil wizards are not always lying: they can give inconsistent random info or the exact info required to ruin a potential strategy as well. Everyone can hear all the information provided by people behind them, but the good wizards don't know who is good or evil.

Hints

Decode these with ROT13 if you'd like a bit of help.

Starting nudge: Hayvxr gur gra-ung chmmyr, gur jvmneqf ner nyybjrq gb fnl nalguvat gurl jnag orsber gurve thrff.

Important observation: N fhpprffshy fgengrtl bayl erdhverf 1 jvmneq gb thrff gurve ung pbeerpgyl. Gur pbeerpg jvmneq qbrf abg unir gb or bar bs gur tbbq jvmneqf.

Nudge on solution path: Vs jr nffhzr rivy jvmneqf nyjnlf thrff gurve ung jebat (bgurejvfr jr nyernql unir n fhpprff), pna jr vqragvsl jub gubfr ner?

Don't scroll down if you still want to try the problem yourself!


 

 

 

 

 

 

 

 

 

Solution

Correctly name all hats in front of you, then guess your hat based on the information from the most recently not-proven-evil wizard.

The pivotal idea is that the good wizard closer to the back of the line can give trusted information about the colour of everyone's hats, and every wizard in front of them must either disagree, revealing themselves to be evil, or agree and guess their hat correctly.

We start with the wizard at the back of the line (wizard 1), who names everyone else's hats and is automatically the most recently not-proven-evil wizard (NPE). They can guess whatever they want. The wizard in front of them (wizard 2) will again name all hats in front, but when guessing the colour of their own hat, they should agree with NPE's info in case both of them are the good wizards.

If wizard 2 doesn't agree with NPE about the colour of their hat, they are clearly evil and all their information should be ignored. If wizard 2 agrees, they become the new NPE, who wizard 3 should trust.

When it's the turn of the good wizard closer to the back, assuming no one earlier has gotten their hat correct, the good wizard will name all hats in front of them correctly and agree with NPE (who may have been lying) for the colour of their own hat, making them the new NPE.

All wizards in front of them now know the correct colour of their hat, so for their guess they must either:

  • agree with NPE and name their hat correctly
  • disagree with NPE and be proven evil

If all evil wizards between the two good wizards are proven evil, then the good wizard closer to the front will agree with NPE and name their hat correctly.

If a wizard deviates from this strategy by, for example, failing to name everyone's hats before guessing their own, they are also obviously evil and can be safely ignored.

Thoughts? Leave a comment

Comments
  1. lumpy — Oct 9, 2025:

    Solved it with a couple of my friends tonight, fun riddle/puzzle! We did need the important observation, we really started going places once we realized that the evil wizards would have to avoid saying their own hat color correctly