When should I stop playing this dice game

diceexpected valuegamblingprobability

The rules are as follows:

You start with \$1 and roll a six-sided die. If you roll anything but a 1, you double your money (so \$2 for the first roll, $4 for the second, and so on). If you roll a 1, you lose all your money. What is the optimal number of times you should roll the die to make the most money?

My initial theory:

The probability of rolling 2-6 consecutively $n$ times is $(\frac{5}{6})^n$; and the probability of rolling a 1 is just $\frac{1}{6}$. So, the expected value is going to be:
$$
E = (\frac{5}{6})^n2^n-\frac{1}{6}2^n \\
=2^n(\frac{5}{6}^n-\frac{1}{6})
$$

Now, if I solve for $n_{L}$ where $E=0$:
$$
0=2^{n_{L}}(\frac{5}{6}^{n_{L}}-\frac{1}{6}) \\
\frac{1}{6}=\frac{5}{6}^{n_{L}} \\
n_{L}=log_{5/6}\frac{1}{6}\\
\approx9.8
$$

Which means I should roll around 9 times to maximize my profit (or maybe 10 if I'm feeling lucky).

However, I tried running a quick simulation and got $n_{L}=5.01 \pm 0.05$ after 10,000 games.

Where did I go wrong? Thank you!

For reference:

import random
import numpy as np

def dice():                                                                    
    return random.randint(1,6)
 
ns=np.array([])
for i in range(10000):
    n=0 
    while dice() != 1:
        n+=1
    ns=np.append(ns,[n])
print(np.average(ns))
print(np.std(ns)/100)

Output

5.0093
0.05511008393207182

Edit:

Here's a more accurate simulation that reflects Ross Millikan's answer for my own reference.

import random
import numpy as np
                                                                               
def dice():
    return random.randint(1,6)
    
trials=np.array([[]])
for i in range(30):
    moneys=np.array([])
    for j in range(100):
        money=1
        numrolls=0
        while numrolls <= i:
            numrolls+=1
            if dice() != 1:
                money=2*money
            else:
                money=0
                break
        moneys = np.append(moneys,[money])
    print("i: "+str(i))
    trial = np.array([i,np.average(moneys)])
    print("money: "+str(np.average(moneys)))
    trials = np.append(trials,trial)            

Output

i: 0
money: 1.74
i: 1
money: 2.48
i: 2
money: 4.88
i: 3
money: 6.56
i: 4
money: 14.08
i: 5
money: 28.8
i: 6
money: 32.0
i: 7
money: 40.96
i: 8
money: 81.92
i: 9
money: 112.64
i: 10
money: 245.76
i: 11
money: 737.28
i: 12
money: 1146.88
i: 13
money: 327.68
i: 14
money: 2293.76
i: 15
money: 3276.8
i: 16
money: 6553.6
i: 17
money: 13107.2
i: 18
money: 26214.4
i: 19
money: 52428.8
i: 20
money: 20971.52
i: 21
money: 0.0
i: 22
money: 83886.08
i: 23
money: 335544.32
i: 24
money: 335544.32
i: 25
money: 671088.64
i: 26
money: 1342177.28
i: 27
money: 8053063.68
i: 28
money: 0.0
i: 29
money: 0.0

Best Answer

Your calculation is incorrect because $2^{n}\cdot \left(\frac 56 \right)^n$ is the expected profit of rolling $n$ times and quitting. You should not subtract the $\frac 162^{n}$ because the loss of that is already reflected.

Planning to roll $n+1$ times is always better than planning to roll $n$ times. If you plan to roll $n$ times your expected return is $2^{n}\cdot \left(\frac 56 \right)^n=\left(\frac 53 \right)^n$. Each additional roll increases your expected return by a factor $\frac 53$ so you should never quit. The mathematical problem with this is that the expected value does not converge, so it is not defined. The psychological problem with this is that eventually you will roll a $1$ and get nothing. This is a variant on the Saint Petersburg paradox.

Simulation is a poor approach for problems like this. If you only try $10000$ or even $10^{100}$ times you will miss the rare event that you avoid rolling $1$ for an enormous time and win huge (assuming you stop).