Evil Wizard Puzzle

Evil Wizard Puzzle Detailed Explanation

An evil wizard had 100 dwarfs as prisoners. One day he calls them and makes them stand according to their height, with the tallest dwarf at the back and the shortest dwarf in the front. He puts a hat on each of the dwarf’s heads but does not let them see the color of the hat. However, the dwarfs can see the hat color of the ones in front of them. He tells the dwarfs that their hats are either black or white, and whoever amongst them can guess the color, is free to go. And the one who guesses wrong will die. The dwarfs are free to discuss a strategy. Devise a strategy where maximum dwarfs can go free.

Evil Wizard Puzzle

The following strategy can enable 99 of the 100 dwarfs to go out free, while the last dwarf gets a 50-50 chance.

Idea:-

  • Since the dwarfs can see the hats in front of them, every dwarf will count the number of a particular color hat that they can see. Let us suppose the dwarfs go with white color.
  • Now the dwarfs are instructed that if they count and find an even number of white hats, they will call out white and if they count an odd number of white hats, they will call out black.
  • Starting from the 100th or the tallest among the dwarfs. He is standing at the back and can see 99 dwarfs in front of him. The dwarf starts counting the white hats, and let us say he saw an even number of white hats and called out white. This may or may not be correct(50-50 chance).
  • However, from this, the subsequent dwarfs can find out the color of their hats.

How?

Let us take the 99th dwarf.

  • The 100th dwarf said white, so the 99th dwarf starts counting. He knows that the one behind him has seen an even number of white hats. If the 99th dwarf also sees an even number of hats, that means his hat is black. And if he sees an odd number of hats that means his hat is white.
  • Let us suppose the 99th dwarf sees odd white hats and calls out white, the next dwarf will start counting. If the 98th dwarf again sees an even number of white hatsthen his hat is white and if it is odd then it is black, and like this, the rest will follow.

Conclusion:-

  • In this case scenario from 1-99, all the dwarfs can guess their color correctly while the 100th dwarf may or may not.

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription