The question is was posted in early Septermber, 2017, **here** and is a undergraduate level probabilty problem:

You’re hanging out with some friends, shooting the breeze and talking sports. One of them brags to the group that he once made 17 free throws in a row after years of not having touched a basketball. You think the claim sounds unlikely, but plausible. Another friend scoffs, thinking it completely impossible. Let’s give your bragging friend the benefit of the doubt and say he’s a 70-percent free-throw shooter.

So, who’s right? What is the number of free throws that a 70-percent shooter would be expected to take before having a streak of 17 makes in a row? And what if his accuracy was a bit worse?

This lends itself to a binomial probability distribution. The shooter has a 70% chance of making and a 30% chance of missing any given free throw. It should be immediate that for the shooter to make 17/17 the probability would be This is roughly a 0.2% chance that the shooter will make 17 in a row while taking 17 shots.

*But that's not the question...*

We want the expected number of attempts until the shooter hits a streak of 17 in a row.

# Expected Values¶

Let's look at a similar problem that is a bit easier to wrap our heads around. I could ask how many times would I need to flip a coin before I got a streak of two heads. Clearly the probability of getting two heads in a row is (0.5)*(0.5) = 0.25, or 25%.

The event we are concerned with is the event that we get two heads in a row. This is unknown so let's represent it with a variable, **X**. Let's say the first flip is a tails, which happens with a probability of 1/2, and is one wasted flip, so now we need **X + 1** flips to get a streak of two heads.

Suppose that the first flip was heads but the second flip was tails. This happens with proabbility 1/4 and we have two wasted flips so we now need **X + 2** further flips.

The only other possibility is that the two flips were both heads, which happens with probability 1/4 and took 2 flips. Summing these up we have

X= (1/2)(X+1) + (1/4)(X + 2) + (1/4)2

Or **X = 6**. **That is, on average, you should expect to get a streak of 2 heads every 6 flips.**

Generalizing this, for the *k*-th flip to be tails the number of flips would be , and one can deduce the expected number of flips to get a streak of heads would be

*What if it's not a fair coin?*¶

Let's start with two flips again and let's assume the head comes up with a 70% chance and tails only 30%. Let **X** be the number of flips needed to get a streak of two heads.

If the first flip is a tail, that happens with a probability of 0.3 and we have wasted a flip so now we need **X + 1** flips. If the first flip is a head, but the second flip is a tail, that happens with a probability of (0.7)(0.3) and we need **X + 2** flips. If two consecutive flips are heads, which happen with probabilty (0.7)(0.7) we acheived success in two flips. Now our equation looks like:

X= (0.3)(X+1) + (0.7)(0.3)(X + 2) + (0.7)(0.7)2

Solving for **X** we get

If let **X** now be 3 heads in a row, we go through the same analysis and end up with an equation that looks like

X= (0.3)(X+1) + (0.7)(0.3)(X + 2) + (0.7)(0.7)(0.3)(X + 3) + (0.7)(0.7)(0.7)3

and solving for **X** we get that it takes approximately 6.38 flips.

In general, if we let *a = probability of heads*, then *(1 - a) = probability of tails* and if we look for a streak of **X = 3** heads the equation above becomes,

More generally, the expected number of flips to get heads is

and solving for **X** we have a nice tidy formula,

We want to explore a 70% free throw shooter. The answer lies below and we use Python to develop the general case. Let's keep in mind there are free throw shooter's in the NBA much worse that 70%.In fact,

**Andre Drummnd of the Detroit Pistons once was shooting around 35%. How long would it take him to hit 17 in a row?**The result is astoundingly funny.

# Solving Using Python¶

In [9]:import numpy as np import pandas as pd import matplotlib.pyplot as plt %matplotlib inline def get_expected_value(a,N): # this method returns the expected number # of flips, free throws or whatever num = (1 - a)*np.sum([k*a**(k-1) for k in range(1,N+1)]) + a**N*N den = 1 - (1-a)*np.sum([a**(k-1) for k in range(1,N+1)]) return num/den def hours_and_minutes_to_acieve(attempts): s = 11.0 # assume 11 seconds per free throw return s*attempts/60.0/60.0