Gambling puzzle A math friend of mine showed me this strange gambling puzzle.  There is a button in a casino and every time you press it you can win either $1$ or $0$ dollars. The probability of winning $1$ dollar depends on how many times you have pressed it so far.  If you press it for the $x$-th time you have probability $x/M$ of winning a dollar. If $x$ gets to $M$ or greater then you just win a dollar every time. 
How many button presses do you expect to have to press to win $N$ dollars?
 A: Caution: This answer is WRONG. But I leave it here since my mistake may help to understand the question correctly. See edit in the last. 
Suppose you play $L$ times. If $L > M$ then you will get
$$ \begin{align*}
E(L) &= \frac{1}{M} + \frac{2}{M} + \cdots + \frac{M}{M} + 1 + \cdots + 1 \\
&= \frac{1}{2}(M + 1) + (L - M)
\end{align*}$$
dollars. Otherwise you will get
$$ \begin{align*}
E(L) &= \frac{1}{M} + \frac{2}{M} + \cdots + \frac{L}{M} \\
&= \frac{1}{2M}L(L + 1)
\end{align*}$$
dollars. Hence, all you need to do is solve $E(L) = N$ for $L$: the answer would be
$$L = \begin{cases}
N + \frac{M - 1}{2} \qquad \left(N > \frac{1 + M}{2}\right) \\
\frac{-1 + \sqrt{1 + 8MN}}{2} \qquad \left(N \leq \frac{1 + M}{2}\right).
\end{cases}$$
Edit I: Thanks to Steven Stadnicki, I realize I was completely wrong. Even in case $N > M$, the expected value is
$$ N \frac{M!}{M^M} + \sum_{k = 1}^{M - 1} (N + k) \frac{M!}{M^M} \sum_{0 < n_1 < \cdots < n_k < M} \prod_{i = 1}^k \frac{M - n_i}{n_i} $$
but I cannot get its simpler form.
Edit II: I conduct a computational experiment and get the average values for $10^4$ trials to guess the expected value $E(M, N)$ as follow.
$$\begin{array}{l|lllll}
M \backslash N & 1 & 2 & 3 & 4 & 5 \\
\hline \\
1 & 1 & 2 & 3 & 4 & 5 \\
2 & 1.5 & 2.5 & 3.5 & 4.5 & 5.5 \\
3 & 1.9 & 3.0 & 4.0 & 5.0 & 6.0 \\
4 & 2.2 & 3.5 & 4.5 & 5.5 & 6.5 \\
5 & 2.5 & 3.9 & 5.0 & 6.0 & 7.0
\end{array}$$
A: In the case of $N \geq M$....
Let $W$ be the winnings after the first $M$ plays. Let $L$ be the number of plays required to win $N$ dollars.
Then $L = M + (N - W)$.
Thus we can compute
$$ E(L) = M + N - E(W) = M + N - \sum_{i=1}^M \frac{i}{M}
= \frac{1}{2}M + N - \frac{1}{2} $$
that is, on average, it takes $\frac{1}{2} M + N - \frac{1}{2}$ plays to win $N$ dollars.
A: The following works under the assumption $N\geq M$.
The first $M-1$ draws are penalized in some way. Denote by $S(r,n)$ the state when there are still $r$ penalized draws to go and already $n$ dollars are won. Denote by $E(r,n)$ the expected number of additional draws when we are in state $S(r,n)$.
In the first $M-1$ draws one gets at most $M-1$ dollars; therefore  $$E(0,n)=N-n\geq 1\qquad(0\leq n\leq M-1)\ .$$
We are asked to compute $E(M-1,0)$. Now the function $E(\cdot,\cdot)$ satisfies the following recursion:
$$E(r,n)=1+\left(1-{r\over M}\right) E(r-1,n+1) +{r\over M}E(r-1,n)\qquad (r\geq 1,\ n\geq0)\ .$$
It so happens that this recursion is solved by
$$E(r,n)=N-n+{r(r+1)\over 2M}\ .$$
(I found this by computing $E(r,n)$ for $r=1, 2, 3$ and guesswork.) It follows that
$$E(M-1,0)=N+{M-1\over2}\ .$$
A: Here is what I did for x≥M.
So N = (1/M + 2/M +...+ M/M) + (x - M)
N=(1 + 2 +...+ M )/M + (x - M)
N=(M^2/2 + M/2)/M + (x - M)
N=(M/2 + 1/2) + x - M
So N = -M/2 + x + 1/2
My apologies for not using the fancy equation writing thing. I have no idea how to do that. I would appreciate it so much if someone sent me a link to some sort of guide.
