Problem
A basketball player is in the gym practicing free throws. He makes his first shot, then misses his second. This player tends to get inside his own head a little bit, so this isn’t good news. Specifically, the probability he hits any subsequent shot is equal to the overall percentage of shots that he’s made thus far. (His neuroses are very exacting.) His coach, who knows his psychological tendency and saw the first two shots, leaves the gym and doesn’t see the next 96 shots. The coach returns, and sees the player make shot No. 99. What is the probability, from the coach’s point of view, that he makes shot No. 100?
Solution
from random import random
runs = 100000
num_99s, num_99_100s = 0, 0
for _ in range(runs):
throws = 2
hits = 1
for _ in range(3, 99):
prob_next = hits/throws
throws += 1
if random() <= prob_next:
hits += 1
if random() <= (hits/throws):
throws += 1
hits += 1
num_99s += 1
if random() <= (hits/throws):
throws += 1
hits += 1
num_99_100s += 1
print(num_99_100s/num_99s)
The probability from the coach’s point of view that the player will make shot No.100 is .666.