• Emily Zhang
  • Fiddler

Where Will the Sorting Hat Put You?

2024 Nov 82024 November 8 Problem Back

This Week's Fiddler

Consider the chance that a given person gets Graphindor, ggg. SotThe next person's chance of getting Graphindor, assuming they have a 25% chance of picking any house, is 1−g4\frac{1-g}{4}41−g​ (the chance the next person wants Graphindor and the current person did not pick Graphindor) plus 1−g3⋅4\frac{1-g}{3\cdot4}3⋅41−g​ (the chance the next person wants not Graphindor but whose choice matches the current person's), which equals 1−g3\frac{1-g}{3}31−g​.

We can start on g=1g=1g=1 and iterate on this process 8 times to find the chance the person immediately before us gets Graphindor. From then, we have a 1−g1-g1−g chance of getting Graphindor as we will always try to pick Graphindor.

from fractions import Fraction

n = 1
g = Fraction(1)
for n in range(2, 10):
    n += 1
    g = (1 - g) / 3

print(1 - g, float(1 - g))
1640/2187 0.7498856881572931

Thus, our chance is 16402187\frac{1640}{2187}21871640​, or about 74.9885688%74.9885688\%74.9885688%.

Answer: 1640/2187 (about 74.9885688%)


Extra Credit

Consider that the only depending factor to the probability is how far away the person yelling "Graphindor" is from you. Being the person right in front of you is equivalent to calculating N=2N=2N=2, being the person before that is equivalent to N=3N=3N=3, etc. So at any NNN, we need to calculate the probabilities from 222 to NNN and average them. The first point where the average exceeds ppp is our answer.

from fractions import Fraction

n = 1
g = Fraction(1)
total = Fraction(0)
p = None

while True:
    n += 1
    g = (1 - g) / 3
    total += (1 - g)
    if n == 9:
        p = 1 - g
        print(p, float(p))
    if p is not None and (total / n) > p:
        print(n + 1, float(total / n))
        break
1640/2187 0.7498856881572931
4922 0.7498856939646413

So N=4922N=4922N=4922 is the first value of NNN greater than 10 where our odds of getting Graphindor is better than ppp. Our odds lie at about 74.9885694%74.9885694\%74.9885694%, exceeding p≈74.9885688%p\approx74.9885688\%p≈74.9885688%.

Answer: 4922

Back to Fiddler list
© 2024 Emily Bradon Zhang·Support Gaza Recovery