To follow up on this thread, we can get a general solution for the expected number of flips to get
n consecutive heads. Start with the simplest case of N=1. If we define the expected number of flips to get 1 head as E, the we can create an equation for E as follows:
Suppose on the first flip we get a head. Then E=1 and the chance of that happening is 1/2. But if we get a tails instead we've used up 1 flip and still have E to go. So we get an equation that defins E in terms of itself like this:
E = 1/2(E+1) + 1/2 (1)
The second term on the right hand side of the equation accounts for the probability of getting a head on flip number 1, and the first term accounts for the probability of not getting a head and still having E flips to go. Solve for E and you find E=2.
Now let's try it for N=2. If we get tails on the first flip we've wasted a one turn and have 1/2(E+1) on the right side again. But if we get a heads then we have to think about what might happen next: there's a 1/2 chance of the next flip being tails, in which case we have to start over again and have wasted 2 flips. But if its heads we're done. Putting this together we have:
E=1/2(E+1) + 1/4(E+2) + 1/4(3)
Solve for E and you get E=6 for n = 3.
For three heads it works out to be E = 1/2(E+1) + 1/4(E+2) + 1/8(E+3) + 1/8(3), which gives E = 14.
The general solution formula for this can be written as:
Hence:
E(1) = 2,
E(2) = 6,
E(3) = 14,
E(4) = 30, etc.