P(bowling a strike) = 70%. Expected number of trials until a perfect game? (10 strikes in a row)
I would also like to learn the generalized form. Odds of an event is P. Formula for expected number of trials to get N success in a row.
P(bowling a strike) = 70%. Expected number of trials until a perfect game? (10 strikes in a row)
I would also like to learn the generalized form. Odds of an event is P. Formula for expected number of trials to get N success in a row.
This is similar to the question of the expected number of flips of a fair coin until we encounter an $n$-streak, except here the probability is 70% instead of 50%.
Assume a probability $p$ of hitting a strike. Let $T_1$ be the expected number of trials before getting the first strike. If the first trial is a strike, then we have only spent one trial and we're done. Otherwise we waste a trial and we start over.
$$T_1 = (p)(1) + (1-p)(1 + T_1) \implies T_1 = \frac{1}{p}$$
Now consider $T_2$, the expected number of trials to get two strikes in a row. There are three possible outcomes, conditional on either making the two strikes immediately, or trying but failing at some point along the line and starting the process over:
$$T_2 = (p)(p)(2) + (p)(1-p)(2+T_2) + (1-p)(1+T_2) \implies T_2 = \frac{1+p}{p^2}$$
For $T_3$, similar idea:
$$T_3 = (p)(p)(p)(3) + (p)(p)(1-p)(3+T_3) + (p)(1-p)(2+T_3) + (1-p)(1+T_3) \\ \implies T_3 = \frac{1+p+p^2}{p^3}$$
In general:
$$T_n = \frac{1+p+p^2+...+p^{n-1}}{p^n} = \frac{p^n-1}{p^n(p-1)} = \frac{1-p^{-n}}{p-1}$$
So for $p=\frac{7}{10}$, we have $T_n = \frac{10}{3}((\frac{10}{7})^n-1)$, and therefore $T_{10} = 114.671105821...$
from random import random
def E(p, n, numTrials = 100000):
tot = 0
for trial in xrange(numTrials):
streak = 0
attempts = 0
while streak < n:
attempts+=1
if random() <= p:
streak+=1
else:
streak = 0
tot += attempts
return tot / float(numTrials)
def closedForm(p,n):
return float(1-p**(-n))/(p-1)
for p,n in [(.7,10), (.5,1), (.5,2)]:
print "E(%s,%s)=%s, verify:%s" % (p,n,E(p,n),closedForm(p,n))
Output:
E(0.7,10)=114.91181, verify:114.671105821
E(0.5,1)=2.00897, verify:2.0
E(0.5,2)=6.00529, verify:6.0