Along with the impressive solutions given earlier, I would propose this solution which simpler to understand and convenient in calculations (especially if the sequence is of length 2 or 3).
P(THH occurring before HHH)
Let us consider the following probabilities:
- probability of getting THH before HHH when HH has occured be $\mu_1$
- probability of getting THH before HHH when HT has occured be $\mu_2$
- probability of getting THH before HHH when TH has occured be $\mu_3$
- probability of getting THH before HHH when TT has occured be $\mu_4$
Let us consider the first case where HH has occurred. If we get a H next, then we have lost and if we get a T, then probability of winning becomes $\mu_2$. That is,
$\mu_1 = p(0) + q\mu_2 $ $\Rightarrow \mu_1 = q\mu_2 \ \ ...(1)$
In our second case, if we get an H after HT, probability of winning is same as starting with TH i.e $\mu_3$; or if we get a T, then probability is same as starting with TT i.e $\mu_4$. So we can write,
$\mu_2 = p\mu_3 + q\mu_4 \ \ ...(2)$
For case 3 we see that if we get an H after TH, then probability of winning becomes 1, and when we get a T, probability of winning is same as $\mu_2$ $\mu_3 = p(1) + q\mu_2 $ $\Rightarrow \mu_3 = p + q\mu_2 \ \ ...(3)$
Going by the same logic, we can write the equation for case 4 as, $\mu_4 = p\mu_3 + q\mu_4 $ $\Rightarrow (1-q)\mu_4 = p\mu_3$ $\Rightarrow p\mu_4 = p\mu_3$ $\Rightarrow \mu_4 = \mu_3 \ \ ...(4)$
Now, using (2) and (4) we get, $\mu_2 = p\mu_3 + q\mu_4$ $\Rightarrow \mu_2 = p\mu_3 + q\mu_3 = (p+q)\mu_3 = \mu_3$
That makes, $\mu_2 = \mu_3 = \mu_4$
Next, solving equation (3) we get, $\mu_2 = p + q\mu_2 $ $\Rightarrow (1-q)\mu_2 = p $ $\Rightarrow p\mu_2 = p $ $\Rightarrow \mu_2 = 1 $
Hence, we get the following values, $\mu_2 = \mu_3 = \mu_4 = 1$ $ And, \ \mu_1 = q\mu_1 = q$
Finally, we can compute the probability of our original event as:
$P(THH \ occurring \ before \ HHH) = P(HH)\mu_1 + P(HT)\mu_2 + P(TH)\mu_3 + P(TT)\mu_4$ $ = p^2\mu_1 + pq\mu_2 + qp\mu_3 + q^2\mu_4$ $ = p^2q + pq + pq + q^2$ $ = q(p^2 + p + p + q)$ $ = q(p^2 + p + 1)$
With $p = 0.7$ and $q = 0.3$, the probability will be $0.657$
Similar approach can be applied for computation of other cases of comparison.