Faraz Gerrard Jamal
1 min readMay 5, 2023

--

Say you have an n-sided die. You keep rolling and sum the values as long as the current roll is larger than the previous. For example, if n = 6 then you might roll 1, 3, 2 and stop or 1, 4, 5, 3 and stop. In the first case, your total sum is 1 + 3 = 4, and in the second case your total sum if 1 + 4 + 5 = 10. What is the expected value of the sum?

Let E(x) be the expected value of a game given that the last rolled i.e., the max roll was x.
E(n) = 0 [As no number is greater than n, hence once we roll an n the game ends]
E(n-1) = 1/n*(E(n) + n)
E(n-2) = 1/n*(E(n-1) + n-1) + 1/n*(E(n) + n) and so on…
E(n-1) = 1
E(n-2) = 2

E(n-3) = 3

so E(1) = n-1
and E(0) = n. [Expected value of game with zero rolls]

Let’s verify via a small simulation in Python :-

import random
n_dice = 10
n_trials = 10000
mega = 0

for _ in range(n_trials):
last = None
while True:
curr = random.randint(1,n_dice)
if last is None or curr > last:
mega+= curr
last = curr
else:
break
print(mega/n_trials) #9.9x for n_dice = 10

And there is our verification :)

--

--