Bernoulli trial n times We are doing a Bernoulli trial unlimited number of times with probability of success $p=0.4$. What is the probability we get $3$ consecutive successes before we get $3$ consecutive failures?
I've used Conditional probability:


*

*Let $W$ be the event: "we got $3$ consecutive success before $3$ consecutive failures"

*Let $S$ be the event: "we succeed in the first trial".

*Let $F$ be the event: "we failed in the first trial".


Then $$P(W) = P(W\mid S) \cdot P(S)+P(W\mid F) \cdot P(F)=P(W\mid S) \cdot \frac25+P(W\mid F)\cdot\frac35$$
To calculate $P(W\mid S)$, let $E$ be the event: $$=\text{ "at the 2nd and 3rd trials we succeed"}$$Then $$P(W\mid S)= P(W\mid SE) \times P(E\mid S)+P(W\mid SE^{c}) \times P(E^{c}|S)= 1 \times 0.16 + P(W\mid F) \times 0.36$$
Now, we calculate $P(W\mid F)$= $$P(W\mid FE) \cdot P(E\mid F)+P(W\mid FE^c) \cdot P(E^c\mid F)$$
what is $P(W\mid FE)=?$
 A: Let $\phi$ be the answer you seek.
Just for notation we'll imagine that this game is a weighted coin toss, with $H$ denoting success.  And, as is standard, we'll denote $q=1-p$. Of course $q=.6$ here, but we'll work in general.
At any point in the game, the only thing that matters is the running string.  That is, if you have followed the path $HHTHTTHTT$ then the only thing that matters is that you have two Tails in a row (so can end the game if you get $T$ on the next toss).  Thus, other than Start and End, there are $4$ states of the game.  $H,T,HH,TT$.  If $S$ is a state let $\phi_S$ denote the probability of winning given that we are in state $S$.
Consider the first toss.  It moves us from Start to either $H$ or $T$.  Accordingly we see that $$\phi= p\phi_H+q\phi_T$$
Similarly we get $$\phi_H=p\phi_{HH}+q\phi_T$$
$$\phi_T=p\phi_{H}+q\phi_{TT}$$
$$\phi_{HH}=p*1+q\phi_T=p+q\phi_T$$
$$\phi_{TT}=p\phi_{H}+q*0=p\phi_H$$
Thus we have $5$ equations in $5$ variables.  It is tedious but not difficult to see that this eventually gives us $$\phi=\frac {p^3+p^2(p+qp)}{1-pq(p+qp)-q(p+qp)}$$
For $p=.4$ this gives $\phi\sim.27128$
Sanity Check:  for $p=.5$ this gives $\phi=.5$ as it should. Also it gives $1$ if $p=1$ and $0$ if $p=0$.  Of course, the above calculation is at risk for algebraic error and should be checked.
A: Let G be the event  "a single failure has just happened". Let $E$ be the desired event. Now, there are three possible scenarios, which we label with $S$: $S=0 \implies$ we fail in the first try (two consecutive failures happen next); $S=1 \implies$ we succeed in the first try; $S=2\implies $ we get less that three fails and less than three successes, so we restart over.
$$P(E\mid G) = \\
P(E \mid G,S=0) P(S=0\mid G)+\\
P(E \mid G,S=1) P(S=1\mid G)+P(E \mid G,S=2) P(S=2\mid G)=\\
0\times q^2+1\times p^3(1+q)+P(E \mid G)(1-q^2-p^3(1+q))$$
Plugging $q=1-p$, this gives
$$P(E\mid G)=\frac{\left( p-2\right)   {{p}^{3}}}{{{p}^{4}}-2  {{p}^{3}}-{{p}^{2}}+2  p-1}$$
Now: $$P(E)=p^3+(1-p^3)P(E\mid G)=-\frac{{{p}^{3}} \left( {{p}^{2}}-3 p+3\right) }{{{p}^{4}}-2{{p}^{3}}-{{p}^{2}}+2 p-1}$$
An alternative way (it gives the same result) is here
