def any():
'''Expected number of letters to get any hero from one of the pools'''
expected = 0
didnt_get = 1 # Odds of not getting it before a roll
for roll in range(1,25):
got = roll/100 # 1% first roll, 2% second roll, etc
expected += didnt_get*roll*got # Odds of getting it exactly this roll, times number of rolls
didnt_get *= (1-got) # Didn't get before, didn't get it now
expected += didnt_get*25*1 # 100% chance to get in the 25th roll
return expected
expected_any = any()
print('Expected number of letters to get ANY hero: {:.2f}'.format(expected_any))
def specific(missing=10):
'''Expected number of letters to get a specific hero from one of the pools'''
expected = 0
didnt_get = 1
for roll in range(1, missing+1):
got = 1/(missing-roll+1)
expected += didnt_get*(roll*expected_any)*got
didnt_get *= (1-got)
return expected
def birthday_paradox(rolled_ladies=0, rolled_gentlemen=0):
'''Expected number of letters to get any pair, alternating ladies and gentlemen'''
expected = 0
didnt_get = 1
for roll in range(0, 10):
# Roll a lady
got_lady = min(1, rolled_gentlemen/(10-rolled_ladies))
expected += didnt_get*((2*roll+1)*expected_any)*got_lady
didnt_get *= (1-got_lady)
rolled_ladies += 1
# Roll a gentleman
got_gentleman = min(1, rolled_ladies/(10-rolled_gentlemen))
expected += didnt_get*((2*roll+2)*expected_any)*got_gentleman
didnt_get *= (1-got_gentleman)
rolled_gentlemen += 1
return expected
expected_pair = birthday_paradox()
print('Expected number of letters to get ANY pair, alternating ladies and gentlemen: {:.2f}'.format(expected_pair))
expected_specific = specific()
print('Expected number of letters to get a SPECIFIC hero: {:.2f}'.format(expected_specific))
print('Expected number of letters to get a SPECIFIC pair: {:.2f}'.format(expected_specific + expected_specific))
print('Expected number of letters to get EVERYTHING: {:.2f}'.format(20*expected_any))