Skip to content
Vamshi Jandhyala

Books · Jane Street: Solutions

Chapter 9

Figurine Figuring

↓ Download PDF handout

Jane received 7878 figurines as gifts this holiday season: 1212 drummers drumming, 1111 pipers piping, 1010 lords a-leaping, etc., down to 11 partridge in a pear tree. They are all mixed together in a big bag. She agrees with her friend Alex that this seems like too many figurines for one person to have, so she decides to give some of her figurines to Alex. Jane will uniformly randomly pull figurines out of the bag one at a time until she pulls out the partridge in a pear tree, and will give Alex all of the figurines she pulled out of the bag (except the partridge, that is Jane’s favourite).

If nn is the maximum number of any one type of ornament that Alex gets, what is the expected value of nn, to seven significant figures?

Solution

Using Monte Carlo simulation, the expected value of nn is 6.87\mathbf{6.87}.

Python code

import random
from collections import Counter

def simulate_picking():
    letters = [chr(65 + i) for i in range(12) for _ in range(i + 1)]
    random.shuffle(letters)
    picks = []
    while True:
        pick = letters.pop()
        picks.append(pick)
        if pick == 'A':
            break
    return max(Counter(picks).values())

def monte_carlo_simulation(num_simulations):
    total_max_picks = 0
    for _ in range(num_simulations):
        total_max_picks += simulate_picking()
    return total_max_picks / num_simulations

num_simulations = 10_000_000
expected_value = monte_carlo_simulation(num_simulations)
print(f"Estimated expected value of the maximum: {expected_value}")