Books · Jane Street: Solutions
Chapter 9
Figurine Figuring
Jane received figurines as gifts this holiday season: drummers drumming, pipers piping, lords a-leaping, etc., down to 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 is the maximum number of any one type of ornament that Alex gets, what is the expected value of , to seven significant figures?
Solution
Using Monte Carlo simulation, the expected value of is .
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}")