# What is the probability that two heads occur before two tails?

A biased coin has probability p of showing heads. We toss the coin repeatedly until two heads or two tails occur in row. What is the probability that two heads occur before two tails?

Consider the four states "HH", "HT", "TH", "TT", representing always the results of the last two tosses. You want the probability of the event $A$ that "HH" occurs before "TT".

After the first two tosses you are in each of these with probabilities $p^2$, $pq$, $pq$ and $q^2$ respectively, where $q=1-p$. Of course if it's "HH" your event does occur, and if it's "TT" it doesn't. So

$$\mathbb P(A) = p^2 + pq \; \mathbb P(A \mid HT) + pq \; \mathbb P(A \mid TH)$$

Given you're in the state "HT", with probability $p$ the next toss is heads, leaving you in the state "TH", while with probability $q$ it's tails, leaving you in "TT", where the event A does not occur. Thus

$$\mathbb P(A \mid HT) = p \; \mathbb P(A \mid TH)$$

Similarly, $$\mathbb P(A \mid TH) = p + q\; \mathbb P(A \mid HT)$$

Solve this pair of equations for $\mathbb P(A \mid HT)$ and $\mathbb P(A \mid TH)$ ...

Suppose you do it right off the bat. (in 2 filps)

$P(hh) = p^2$

in 3 flips? $P(thh) = p^2(1-p)$ (this is the only way to win in exactly 3 flips)

4 flips? $P(hthh) = p^3(1-p)$ (this is the only way to win in exactly 4 flips)

In order to win in $n+2$ flips, the first $n$ flips must alternate $hththththth$

$2k$ flips $= p^{k+1}(1-p)^{k-1}$

$2k+1$ flips $p^{k+1}(1-p)^{k}$

$\sum_\limits{k=1}^{\infty} p^{k+1}[(1-p)^{k-1}+(1-p)^k]$

$\frac {p^2(2-p)}{1-p(1-p)}$