Expected number of coin flips to get two consecutive heads
Let each independent coin flip be heads with probability p, where 0 < p <= 1.
Starting with no previous heads, return the expected number of flips until two
consecutive heads first appear. The fair-coin theorem is the special case
p = 1/2, whose answer is 6.
The two heads must be consecutive, so overlapping trials are dependent. Do not
model this as independent attempts with probability p * p and expectation
1 / (p * p).
Examples
Input:0.01
Output:10100
Input:0.02
Output:2550
Hints
Use states for zero and one trailing heads.
For a biased coin, write `E0 = 1 + p E1 + (1-p) E0` and `E1 = 1 + (1-p) E0`.
Solve the equations to obtain `E0 = (1+p)/(p*p)`.
Expected number of coin flips to get two consecutive heads
Let each independent coin flip be heads with probability `p`, where `0 < p <= 1`.