TITLE: A gambler with the devil's luck?
QUESTION [26 upvotes]: A gambler with $1$ dollar intends to make repeated bets of $1$ dollar until he wins $20$ dollars or is ruined. Probabilities of  win/loss are $p$ and $(1-p)$, and each bet brings a gain/loss of $1$ dollar. 
Unfortunately, the devil is active, and ensures that every time he reaches $19, he loses! Obviously, the poor guy will get ruined sooner or later!
The question is, what is the expected number of bets he makes until he is ruined?

REPLY [3 votes]: If the devil intervenes when you reach level $d$ (here $d=19$), the mean time before ruin occurs is
$$
E_1(T)=\frac1{1-2p}\,\left(1-2p\left(\frac{p}{1-p}\right)^{d-1}\right).
$$
If $p=\frac12$, one should consider the limit of this when $p\to\frac12$, which yields
$$
E_1(T)=2d-1.
$$
Sanity checks: If $d=1$ then $E_1(T)=1$ for every $p$ (why?). If $p\lt\frac12$, $E_1(T)$ stays bounded when $d\to\infty$ (why?). If $p\gt\frac12$, $E_1(T)$ grows exponentially fast when $d\to\infty$ (why?).