Think of this problem instead as a random walk along the number line, starting at zero. If the walker ever returns to zero, then success is achieved. Let x_{i} be the probability of success from point i on the number line. Let p be the probability that the walker moves to the right. Let's also let p be the lesser of the probabilities of flipping heads and tails.

I hope I won't have to prove that x_{-1}=1. In other words, the gravity of the greater probability of q will pull the walker to the right, over the long run. So if his first move is to the left, he will eventually make it back to point 0. For the same reason, given a casino game with a house advantage, the house always wins in the long run. If the player wins his first bet, if he plays indefinitely, he will eventually lose it back.

That said, we can set up the following equations:

x_{0} = p + q×x_{1}

x_{1} = p + q×x_{2}

x_{2} = p×x_{1} + q×x_{3}

x_{3} = p×x_{2} + q×x_{4}

.

.

.

Next, take the sum of both sides.

Let E = x_{0} + x_{1} + x_{2} + ...

E = 2p + pE -p×x_{0} + qE - q×x_{0}

E = 2p + E×(p+q) - x_{0}×(p+q)

E = 2p + E - x_{0} (because p+q=1)

0 = 2p - x_{0}

x_{0} = 2p
So the answer is 2p.

Below are the results of computer trials which have verified the answer above. For each probability p 100,000 trials were conducted, in which a trial ended when either the number of heads equalled the number of tails, or the difference was more than 25. It seems reasonable to assume that for p<=.4 if the difference ever equals 25 it is very unlikely that the gap ever be closed. A 'win' means the number of heads was ever equal to the number of tails. The number of losses would be 100,000 minus the number of wins.

p wins ----- ------ 0.4 80058 0.3 59799 0.2 39957 0.1 19803

If you don't buy my solution, I have posted altnernate solutions by Richard Tucker and David Beim.

Thanks to Guy de Kindler for providing the problem and Richard Tucker and David Beim for the alternate solutions.

Michael Shackleford, A.S.A.