Where Will The Seven Dwarfs Sleep Tonight?

A FiveThirtyEight Riddler puzzle.

By Vamshi Jandhyala in mathematics Riddler

January 5, 2018

Riddler Express

A kite shape is inscribed in a circle, as shown below.

What is the kite’s area?

A rectangle is drawn inside a quarter circle, as shown below.

What is the rectangle’s area?

Solution

The longer diagonal of the kite is the diameter of the circle because of symmetry. Therefore, one half of a kite is a right angled triangle. The area of the kite is $40$}.

The diagonal of the rectangle is equal to the radius of the quadrant = $13$. The length of the rectangle is $12$ by Pythagoras theorem. Therefor the area of the rectangle is $60$.

Riddler Classic

Each of the seven dwarfs sleeps in his own bed in a shared dormitory. Every night, they retire to bed one at a time, always in the same sequential order, with the youngest dwarf retiring first and the oldest retiring last. On a particular evening, the youngest dwarf is in a jolly mood. He decides not to go to his own bed but rather to choose one at random from among the other six beds. As each of the other dwarfs retires, he chooses his own bed if it is not occupied, and otherwise chooses another unoccupied bed at random.

What is the probability that the oldest dwarf sleeps in his own bed? What is the expected number of dwarfs who do not sleep in their own beds?

Solution

from random import sample

runs = 100000
num_dwarfs = 7
cnt_last_wrong_bed = 0
cnt_wrong_beds = 0
for _ in range(runs):
    num_wrong_beds = 1
    remaining_beds = set(range(num_dwarfs))
    b = sample(range(1, num_dwarfs), 1)[0]
    remaining_beds.discard(b)
    for i in range(1, num_dwarfs-1):
        if i in remaining_beds:
            remaining_beds.discard(i)
        else:
            num_wrong_beds += 1
            b = sample(remaining_beds, 1)[0]
            remaining_beds.discard(b)
    if num_dwarfs-1 not in remaining_beds:
        cnt_last_wrong_bed += 1
        num_wrong_beds += 1
    cnt_wrong_beds += num_wrong_beds
print("Expected number of wrong beds: ", cnt_wrong_beds/runs)
print("Chance of oldest in own bed: ", 1 - cnt_last_wrong_bed/runs)

Expected number of wrong beds: $2.86$. Chance of oldest in own bed: $0.4168$.