5
$\begingroup$

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
$\endgroup$
2
  • $\begingroup$ I'm not fluent in python, but it seems to me that what your code actually does is compute the expected number of rolls until you hit a $1$, which is 6 (so 5 rolls before the $1$). $\endgroup$
    – lc2r43
    Apr 30, 2021 at 4:08
  • $\begingroup$ You're totally right. That accounts for the discrepancy. Thanks! $\endgroup$
    – siberowl
    Apr 30, 2021 at 4:32

2 Answers 2

6
$\begingroup$

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).

$\endgroup$
6
  • $\begingroup$ Thanks for the answer! Intuitively, wouldn't the expected value as $n$ goes to infinity be zero though? $\endgroup$
    – siberowl
    Apr 30, 2021 at 4:29
  • $\begingroup$ No, it grows without bound. The chance of getting anything goes to $0$, but the something you get grows faster, so the expected value grows without bound. $\endgroup$ Apr 30, 2021 at 4:36
  • $\begingroup$ Sorry, I'm a bit confused. The St. Petersburg problem goes to infinity because you never lose the money (there is no minus term) which makes sense intuitively as well. In this case, wouldn't I have a minus term? Also, the probability of rolling a 1 as $n$ goes to infinity is 100%. So you will always end up losing if you keep rolling. I based this idea on this math.stackexchange.com/questions/1974265/… $\endgroup$
    – siberowl
    Apr 30, 2021 at 4:47
  • $\begingroup$ The idea in St. Petersburg is also that the expected value is not bounded. You are right that you never lose money there, but the increasing payoff with decreasing probability is the same. $\endgroup$ Apr 30, 2021 at 5:00
  • $\begingroup$ It took me a while, but I finally got it...wow that was crazy. I tried running a simulation where I'd roll from 1 to 100 times 100 each, and I finally understood what you meant after seeing the average profit shoot up until it just hit zero. I never really thought about problems that aren't fit for simulations till now. Frustrating since my first mathematical guess was that it diverges, but my intuition said no so I tried to modify it haha. Thank you so much! $\endgroup$
    – siberowl
    Apr 30, 2021 at 5:34
2
$\begingroup$

Your code is calculating the average number of rolls where you successfully cash out but it doesn't account for the fact that the prize doubles at each step. The expected value does and so taking more risks for the much larger reward is optimal at each step.

$\endgroup$
2
  • $\begingroup$ Oh I see, that makes sense. Thank you! I wonder if my theory is still correct, and if I should still be choosing 9 over 5 rolls. $\endgroup$
    – siberowl
    Apr 30, 2021 at 4:31
  • $\begingroup$ Relevant fundamental principle? or not really? $\endgroup$
    – BCLC
    May 5, 2021 at 7:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .