I consider a gambler's ruin problem in which
- the gambler has $k$ units of money to start with
- the gambler wins 1 unit of money with probability $\sigma$ and loses 1 unit of money with probability $1-\sigma$
- maximum number of trials is $n$
- game stops if the gambler is ruined, attains $2k$ units, or has laid a bet $n$ times; whichever of these happens first.
I have derived the following generating function which codes the expected number of rounds. \begin{align} D_k(z) = & \frac{z}{(1-z)^2}\left\lbrace 1 - \frac{2^k \sigma ^k z^k}{\left(1+ \sqrt{1-4\sigma \left(1 - \sigma\right) z^2}\right)^k + \left(1- \sqrt{1-4\sigma \left(1 - \sigma\right) z^2}\right)^k} \right\rbrace + \\ \nonumber & \frac{z}{(1-z)^2} \left\lbrace \frac{2^k \left(1 - \sigma\right)^k z^k}{\left(1+ \sqrt{1-4\sigma \left(1 - \sigma\right) z^2}\right)^k + \left(1- \sqrt{1-4\sigma \left(1 - \sigma\right) z^2}\right)^k} \right\rbrace \end{align} To find the expected number for various values of $n$, I think I should differentiate it $n$ times, divide by $n!$ and evaluate it at $z=0$. Direct differentiation leads (me) to intractable expressions. I wonder if there are other methods.