# Expected value for a fair die game

You roll a fair die until the cumulative sum rolled so far is a multiple of 3. You get \$1 for each roll. What is the expected amount you will get?

I started by finding the probability of the game ending with "i" rolls, P(i). If I have this, I can then find the expectation. P(1), the probability of the game ending in 1 turn is 1/3 as either 3 or 6 can end the game. I continued doing this for P(2), P(3), etc., by writing down the sample space. It was too cumbersome and didn't know if it would end. Is there a more structured way to solve this problem?

• This is not a homework question. I was asked this question in an interview but I am not sure how to solve this. Commented Oct 2, 2023 at 4:49
• Please add the self-study tag & read its wiki. Then tell us what you understand thus far, what you've tried & where you're stuck. We'll provide hints to help you get unstuck. Please make these changes as just posting your homework & hoping someone will do it for you is grounds for closing. Note that this policy and the self-study tag also apply in your situation. Commented Oct 2, 2023 at 5:46
• Also, please clarify what you mean by "a dice". The singular of "dice" is "die", so are you rolling one die or multiple ones? If a single die, what do you mean by "the sum of the values that show up"? Do you mean the cumulative sum rolled so far? Commented Oct 2, 2023 at 5:48
• @StephanKolassa, thank you for the suggestions. I have added the tag, changed the dice to die and described my approach. Commented Oct 2, 2023 at 17:24
• At each step, the chance that the cumulative sum will be a multiple of 3 is always 1/3, no matter what the cumulative sum currently is. Thus, you are really rolling a three-sided die until a specified side appears.
– whuber
Commented Oct 2, 2023 at 17:59

You can make this very complicated, but the main trick is probably to recognize that

"independent from the current cumulative value there is a 1/3-th probability that a roll ends the game"

Then this game has a distribution of number of dice rolls that is geometric distributed with parameter $$p=1/3$$ and this has an expectation value of $$1/p = 3$$.

upd Sorry for making the solution so complicated, whereas the result is definitely true.

We use DiscreteMarkovProcess to model the process:

Mathematica code:

Clear["Global*"];
transferMatrix = ConstantArray[1/3, {3, 3}];
transferMatrix[[3]] = {0, 0, 1};
(transferMatrix) // MatrixForm
\[CurlyPhi] = DiscreteMarkovProcess[{1, 0, 0}, transferMatrix];

VisualizeOneMarkovProcess[\[CurlyPhi]_] :=
Graph[\[CurlyPhi], VertexLabels -> Placed["Name", Center],
VertexSize -> Large,
EdgeLabels ->
With[{sm =
MarkovProcessProperties[\[CurlyPhi], "TransitionMatrix"],
statesNumber =
Length@MarkovProcessProperties[\[CurlyPhi],
"InitialProbabilities"]},
Flatten@Table[
If[sm[[i, j]] != 0, DirectedEdge[i, j] -> sm[[i, j]], {}], {i,
statesNumber}, {j, statesNumber}]], ImageSize -> Medium]

VisualizeOneMarkovProcess[\[CurlyPhi]]


Then we calculate the mean of the FirstPassageTime to the absorb state.

\[ScriptCapitalD] = FirstPassageTimeDistribution[\[CurlyPhi], 3];
mypdf = PDF[\[ScriptCapitalD], k]
(* \[Piecewise] 2^(-1+k) 3^-k   k>0    0    True *)

Mean[\[ScriptCapitalD]]   (* 3 *)
`

So the answer is $$\color{blue}{3}$$

• Code-only answers are useful but not really on topic here on CV when they have contain statistical explanation or insight: consider posting your Mathematica solutions on the Mathematica site instead.
– whuber
Commented Mar 5 at 16:31