# Expected value of suming up to 6 tossing a coin, where each tail adds one and each heads subtracts one(can't go less than zero points)

So, I was playing this video game where you could use a jewel to add value to an item. Item values goes from +0 to +6. Each time you use the jewel you have a 50% chance of success, now, the Expected value of jewels I should use to get it to +6 would be easily calculated, it's 12. (6/0.5).

But here's the thing, each time you miss, it subtracts one, so if your item is +2 and you fail, it goes back to being +1. The only exception is when it is +0, as it cannot go any lower.

So my question is, how do i calculate this number analytically? I ran it through python and the result is 42. There's a second case where the chance of success is now 75%, in which my script gives me an expected value of 11.

Thanks for the help!

For $$k=0,1,\dots,6$$ let $$e_k$$ be the expected number of rolls to get to $$6$$. We have \begin{align} e_6&=0\\ e_5&=1+\frac12e_4+\frac12e_6\\ e_4&=1+\frac12e_3+\frac12e_5\\ e_3&=1+\frac12e_2+\frac12e_4\\ e_2&=1+\frac12e_1+\frac12e_3\\ e_1&=1+\frac12e_0+\frac12e_2\\ e_0&=1+\frac12e_0+\frac12e_1 \end{align}

and we want the value of $$e_0$$.

The equation for $$e_5$$ for example, comes from the fact that we always have to make $$1$$ roll and after that the value will be either $$4$$ or $$6$$, each with probability $$\frac12$$.

To solve, this system, use the last equation to express $$e_1$$ in terms of $$e_0$$, then the previous one to express $$e_2$$ in terms of $$e_0$$ and so on. Eventually, we get $$e_6$$ in terms of $$e_0$$, and $$e_6$$ is known, so we can calculate $$e_0$$.

I get, successively, \begin{align} e_1&=e_0-2\\ e_2&=e_0-6\\ e_3&=e_0-12\\ e_4&=e_0-20\\ e_5&=e_0-30\\ e_6&=e_0-42\\ \end{align} so that the expected number of rolls is $$42$$.

So, messing up with the numbers, and saying I have to get the item to just +1, or +2, and so on, i get the series, 2 6 12 20 30 42 and so on, which represents exactly n^2 + n So i guess that's the analytic result, still not sure how to get there.

• Now I see that you have the right sequence. If you mean that you want to prove that the expected number of rolls to get to $n$ is $n^2+n$, you can do it by strong induction. Apr 12 '20 at 16:45