# Expected sum of all the n-sided dice rolls until we get n

So the problem is the following. We have an $n$-sided die. We throw it until we get $n$. What's n, if the expected sum of all the throws including the $n$ one is $21$.

Now, I did manage to solve it by assuming we throw the dice m times, then getting the expected value of a single throw and multiplying it with m to get the expected sum of all the throws. Then I just needed to get the expected m for an n sided die. However, the solution provided with the problem seems to be much shorter and I don't really understand how it works. It goes like this:

Let X be a random variable representing the sum. Let Y be a random variable representing the value of the first throw. Then we can write the expected value of X using the law of total expectation like this:

$EX=E(X|Y=1)P(Y=1) + ...+E(X|Y=n)P(Y=n)$

So far so good I thought. But then they substitute $EX$ with $21$ and do this:

$21 = (21+1)\frac{1}{n}+...+(21+n-1)\frac{1}{n}+1$

Solving it for $n$ does produce the correct result ($6$), but I don't understand the reasoning behind $E(X|Y=a)=(21+a)$

Surely the expected value of $X$ already takes into account that the first throw will add something into the sum, right? So how is the expected value of $X$ GREATER than $21$ if the first throw gave the lowest possible amount?

Using the same logic I tried to solve it by calculating the expected value for each throw ($\frac{n+1}{2}$) and then replacing $E(X|Y=a)$ with $(21+a-\frac{n+1}{2})$ my logic being that if we get $a$ and we expect $\frac{n+1}{2}$, the sum goes up or down by the same amount that $a$ differs from the expected value.

Solving it like that, however, produces a wrong result ($-41$).

So, where did I make a mistake?

• why add 1 at the end and not 1+21/n? And for your second approach: I get 21 on both sides, because the n cancel out so I think it would be correct but it doesn't tell you anything about n. If I plug in your given formula, I do get 6 by the way. Commented Jan 23, 2014 at 15:13
• The 1 at the end is because if the first throw lands on n, then we don't throw anymore hence the expected sum is n. Multiply that with 1/n (the probability of n happening on the first throw) and you get 1. Commented Jan 23, 2014 at 15:49