Expected duration of symmetric gambler's ruin (source code)

= Expected duration of symmetric gambler's ruin

For a symmetric <random walk> started at $i\in\{-a,\ldots,b\}$ and stopped on first reaching $-a$ or $b$, the <mean> duration is
$$
\mathbb E_iT=(i+a)(b-i).
$$
In particular, $\mathbb E_0T=ab$. This follows either from the first-step <recurrence> or by stopping the <Martingale> $S_n^2-n$.