Tuesday 16 August 2016

Wizards and Drawves

Problem

There is a village of wizards and a village of N dwarves.
Once a year, the wizards go over to the village of dwarves and line all the dwarves up in increasing height order, such that each dwarf can only see the dwarves shorter than himself.
The wizards have an infinite supply of white and black hats. They place either a white or black hat on the head of each dwarf. Then, starting with the tallest dwarf (in the back of the line), they ask each what color hat he is wearing. If the dwarf answers incorrectly, the wizards kill him (the other dwarves can hear his answer, but can’t tell if he was killed or not). What is the most number of dwarves that will be killed using this optimal strategy?
Do note that the dwarves already know that the wizards will do as stated above. So, they can get together and devise an optimal strategy to minimize the people that get killed.


Answer : 1

Solution Approach:

Let white be encoded as 1 and black as 0.
The tallest dwarf sums up the blacks and whites in front of him,divides it by 2 and calls out white or black depending on the remainder 1 or 0
The second one can know his answer

But now the second dwarf can know the color of his own hat by adding up the sum of 0s and 1s ahead of him and finding the remainder with 2 and comparing it with the answer given by the dwarf behind him. If the answer is same, he is wearing a black hat, else he is wearing a white hat, which he calls out with full certainty, and survives.

Hence using this strategy, at most 1 dwarf is killed with probability half.

1 comment:

  1. Online Casinos With Cash in Coin Casino
    Looking to get in on the 인카지노 action 바카라 사이트 at online casinos? Learn how to play for real money at casinos with cash in casino งานออนไลน์ games. Discover all the details

    ReplyDelete