TITLE: Convergence of winning probability in a one-player dice-throwing game
QUESTION [25 upvotes]: In this (one-player) game, the player starts with a total of $n$ points.  On each turn, they choose to throw either a four-, six-, or eight-sided die, and then subtract the number thrown from their point total.  The game continues until the player's point total reaches zero exactly, and they win, or falls below zero, in which case they lose.
The strategy does not seem obvious.  (Even for the simple case of $n=5$, one must do a calculation.)  And dynamic programming techniques show that the strategy is not straightforward.  For $n≤20$, the four-sided die is optimal, except for $n=5, 6, 13, 20$, where the six-sided die is optimal, and $n=8, 14, 16$, where the eight-sided die is optimal.
For large $n$, the probability of winning approaches $0.456615178766744$, which is not a number that I recognize.  (The ISC does not recognize it either.)
It's not particularly surprising that the probability of winning converges as $n$ increases, because the probability of winning with $n$ points is the mean of probability of winning with $n-i$ points, taken over a small range of $i$.  Considering the probabilities as a sequence, each element lies inside the range of the previous few elements, and tends to be in the middle of that range. As one goes farther out in the sequence, variations away from the mean tend to be damped out.
My questions are:


What's this $0.456615178766744$?  (For a single $d$-sided die the probability of winning approaches $\frac 2{d+1}$, but for more dice the problem seems harder.)
Is there any regularity to the optimal move, as $n$ increases?
Is there any good way estimate a good strategy, short of exhaustive computer calculations?  For example, in the $n=7$ situation, the four-sided die is significantly better than the six-sided die.  Is there some way to see this, or at least to guess that it is so?
Someone must have studied this before.  Does the problem have a name?  Can someone give me a reference to the literature?

REPLY [2 votes]: Here's some Python code that may be of interest for empirical exploration. There are various magic numbers in it that may well be ill-chosen.
You need to have the mpmath library installed.
import collections,itertools
import mpmath
def gend(dice):
    n = max(dice)
    t = (n-1)*[mpmath.mpf(0)] + [mpmath.mpf(1)]
    yield (1,0)
    while True:
        u = max((sum(t[-d:])/mpmath.mpf(d),-d) for
 d in dice)
        u = (u[0],-u[1])
        yield u
        del t[0]
        t.append(u[0])
def analyse(dice, maxbits=100000, maxiters=100000):
    miniters = 1000
    bits = 1000
    while bits <= maxbits:
        print(f"Trying {bits} bits, up to {maxiters} iterations.")
        mp.prec = bits
        prev,nits = 0,0
        dseq = []
        tol = mpmath.mpf(0.5)**(bits-10)
        nconv = 0
        for (prob,die) in itertools.islice(gend(dice), maxiters):
            if abs(prob-prev) <= tol and nits >= miniters:
                nconv += 1
                if nconv > max(dice): break
            else: nconv = 0
            dseq.append(die)
            prev = prob
            nits += 1
        if nconv <= max(dice):
            print("Not converged; giving up; try again with larger maxiters.")
            return
        maxcoeff=2**(bits//5)
        tol=mpmath.mpf(0.5)**int(bits*0.45)
        print(f"Converged; invoking findpoly with maxcoeff~=2^{mpmath.mag(maxcoeff)}, tol~=2^{mpmath.mag(tol)}.")
        expr = mpmath.findpoly(prob, maxcoeff=maxcoeff, tol=tol, maxsteps=maxbits)
        if not expr:
            if bits >= maxbits:
                print("No rational found; try again with larger maxbits?")
                return
            print(f"No rational found with {bits} bits; trying with more.")
            bits = min(round(1.5*bits), maxbits)
            continue
        num = abs(expr[1])
        den = abs(expr[0])
        print(f"Likely rational value found: {num}/{den}")
        print(f"Error is about {mpmath.nstr(abs(mpmath.mpf(num)/mpmath.mpf(den)-prob),10)}.")
        break
    j = len(dseq)-2
    while j>10*max(dice) and dseq[j] == dseq[-1]: j -= 1
    j = int(0.8*j)
    dseq = dseq[:j]
    startpoint = len(dseq) // 10
    maxperiod = len(dseq) // 10
    period = None
    print(f"Attempting period-finding with {len(dseq)} values, start=maxperiod={maxperiod}.")
    for tl in range(1,maxperiod+1):
        tail = dseq[-tl:]
        reps = (len(dseq)-startpoint) // tl
        longtail = dseq[-(reps*tl):]
        if longtail == reps*tail:
            print("Period", tl)
            period = tl
            break
    else: print("No period found with this many iterations.")
    if period is not None:
        for i in range(len(dseq)-2*period):
            p = dseq[i:i+period]
            r = (len(dseq)-(i+period)) // period
            if dseq[i+period:i+period*(1+r)] == r*p:
                print("Repeating period starts at", i)
                print("Initial transient:", dseq[:i])
                print("Repeating seq:", ' '.join(map(str,p)))
                print("Counts:", collections.Counter(p))
                break


Invoke this with e.g. analyse((4,6,8)).
On the machine I'm using right now, for instance, that call takes about 0.4 seconds and outputs the folllowing:
Trying 1000 bits, up to 100000 iterations.
Converged; invoking findpoly with maxcoeff~=2^201, tol~=2^-449.
No rational found with 1000 bits; trying with more.
Trying 1500 bits, up to 100000 iterations.
Converged; invoking findpoly with maxcoeff~=2^301, tol~=2^-674.
Likely rational value found: 53593778027393979383062834089689687375851958941331473223707343944117988244200/117371871369111168311975072842802096714042245341293610168598354761946856284327
Error is about 1.425530482e-452.
Attempting period-finding with 2032 values, start=maxperiod=203.
Period 116
Repeating period starts at 1
Initial transient: [0]
Repeating seq: 4 4 4 4 6 6 4 8 4 4 4 4 6 8 4 8 4 4 4 6 6 8 4 8 4 4 4 6 6 8 4 8 4 4 4 6 4 8 4 8 4 4 4 6 4 8 4 4 4 4 4 6 4 8 4 4 4 4 4 6 4 8 4 4 4 4 6 8 4 8 4 4 4 4 6 8 4 8 4 4 4 6 6 8 4 8 4 4 4 6 4 8 4 8 4 4 4 6 4 8 4 8 4 4 4 6 4 8 4 4 4 4 4 6 4 8
Counts: Counter({4: 73, 8: 24, 6: 19})

In more difficult cases it takes longer, of course. For instance, analyse((3,6)) takes about 42 seconds before finding the thousands-of-digits-long rational discussed elsewhere in comments; it ends up using about 38k bits of precision. (The repeating period is of length 743, it starts at place 3635, and it contains 555 three and 188 sixes.)

[Important confession: in a previous version of this code the convergence check was more simple-minded than the one above. Many of the calculations reported below used that previous version. I don't think any of the results are invalid for that reason, but if you are going to rely on what follows for something important (how??) you might want to double-check using the code as it now stands above.]
Some empirical findings from this (some of which have already been reported in other answers, comments thereon, or comments on the original question, but it seems worth putting them together):
We already know (with proof!) what {k} and {2,k} do; see my other answer.
{3,k}:

k=4: 512/891, period 3 [344], starting at place 6
k=5: 9344/17145, period 5 [53333], starting at place 5
k=6: thousands of digits, period 743, starting at place 3635
k=7: 2653/5002, period 7 [3333337], starting at place 1
k=8: 136/261, period 8 [33333338], starting at place 1
k=9: 361/697, period 9 [333333339], starting at place 1
k=10: 410/791, period 10 [333333333A], starting at place 1
the pattern in the periods (and the existence of "reasonable" rational limits) continues at least to k=20

So that's interesting: for $k>6$ everything is lovely (maybe there's a theorem to be proved...), for $k=6$ it's horrible, and for $k<6$ things are fairly nice but it takes a little while to settle down rather than being immediately periodic. I guess maybe when you have {m,n} with n>2m you're forced to take the m-sided die for the first while, and maybe that helps get things into a nice state.
For {4,k}:

k=5: 5041105/11010048, period 4 [4555] starting at 20
k=6: 2074375/4611072, period 6 [644444] starting at 6
k=7: 4779071465392056377836750715/11212131909551128478625038336, period 7 [7444444] starting at 49
k=8: 155 digits, period 199 starting at 33
k=9: 261077813956747/618161221140480, period 9 [944444444] starting at 18
k=10: 555831345/1323302912, period 10 [A444444444] starting at 10
k=11: 61 digits, period 98 starting at 1
k=12: 469 digits, period 71 starting at 627
k=13: 87922601/212701839, period 13 [444444444444D] starting at 1
k=14: 145186048563612283212299803/352208024470599386445905920, period 14 starting at 28
k=15: 83 digits, period 164 starting at 1

So much for things being nice when the ratio of dice is large. No very obvious patterns here.
Now for {5,k}:

k=6: some rather alarming things happen here (maybe there's a bug in my code); see below.
k=7: no rational found up to 100k bits (looking for numerators and denominators up to about 6000 decimal digits long)
k=8: no rational found up to 100k bits
k=9: no rational found up to 100k bits

That {5,6} case is scary. Depending on exactly what parameters I feed into my analyse function, it finds various different rational numbers of different sizes, with lots of factors of 10 in the denominator, all of them approximating the limits it finds well enough to convince mpmath that they're real. I suspect they may all be bogus. I would be extremely interested if someone else were to look into this case using different code.
(See below for more about this case.)
For other values of $k$, $\{5,k\}$ seems not to produce a rational limit of at-all-reasonable size. Perhaps these values genuinely aren't rational? Or perhaps it's just that some key thing grows rather rapidly with the number of faces on the smallest die.
[UPDATE added later: I've set my code running for quite a long time on {5,7}. On current evidence it seems there's no rational limit with fewer than about 76000 decimal digits. UPDATE later still: still none up to about 114000 digits. UPDATE even laterer: none up to about 171000 digits.]

Let's look at some larger sets of dice. We already know what $\{k,k+1,\dots,2k-1\}$ does, and that adding other larger dice to that set doesn't change anything. Other than avoiding these, there's no particular logic to which sets I've looked at below. There are a couple of patterns that seem to be present...
With {2,4,6} we get 86/123 and a repeating period of 6 [222426] starting at the beginning.
With {2,4,7} we get 623/884 and a repeating period of 7 [2224227] starting at the beginning.
With {2,4,8} we get 1400/2003 and a repeating period of 8 [22242228] starting at the beginning.
There seems to be a pattern here, in the repeating periods at least. But...
With {2,4,9} we get 709/1023 and a repeating period of 9 [222422249] starting at the beginning.
With {2,4,10} we get 14090/20813 and a repeating period of 10 [222422242A] starting at the beginning.
With {2,4,11} we get 31097/44552 and a repeating period of 11 [2224222422B] starting at the beginning.
With {2,4,12} we get 22580/32399 and a repeating period of 12 [22242224222C] starting at the beginning.
So the pattern is at least a little more complicated than it first appears.
With {3,4,6} we get 52544/90801 (quite a lot of 3s in the denominator) and a repeating period of 6 [644344] starting at index 6.
With {3,4,7} we get 196/339 and a repeating period of 7 [3343374] starting at index 2.
With {3,4,8} we get 40/69 and a repeating period of 8 [33343348] starting at the beginning.
With {3,6,9} we get 2235/4219 and a repeating period of 9 [333336339] starting at the beginning. The period here (333, 336, 339) is suggestive, and this sort of structure has appeared in other repeating periods -- e.g., 22242228 for {2,4,8} -- but this may just be the Law of Small Numbers at work.
With {4,5,6} we get 5675/11776 (that's a lot of 2s in the denominator!) and a repeating period of length 4 [4566] starting at index 8.
With {4,5,7} we get 164275/349696 (again lots of 2s in the denominator) and a repeating period of length 7 [7455455] starting at index 7.
{4,6,8} -- the original combination of dice in the question -- is described above; we get a period of length 116.
{2,4,6,8,10,12} has limit 46124/65305 and period 22 24 26 28 2A 2C, which is kinda nice and, along with what we saw above for {2,4,6}, suggests an obvious pattern in the periods -- which does indeed also hold for {2,4,6,8} and {2,4,6,8,10}, as well as {2,4}. It wouldn't surprise me if this one were provable without too much pain.
Here's an interestingly suggestive set -- I report only the periodic patterns and not the limits; all periodic patterns start at the beginning except for {4,6,10} where the "x"s indicate where the repeating pattern actually begins.
{4,6,8}: horrible (see above)
{4,6,10}: x x 4 4 6 6 4 4 4 10 4 6
{4,6,12}: 4 4 4 4 6 6 4 4 4 4 4 12
{4,6,14}: 4 4 4 4 6 6 4 4 4 4 4 6 4 14
{4,6,16}: 4 4 4 4 6 6 4 4 4 4 4 6 4 4 4 16
{4,6,18}: 4 4 4 4 6 6 4 4 4 4 4 6 4 4 4 4 4 18
It sure looks like there's a regular pattern there starting at 14 and arguably at 12; even {4,6,10} kinda fits. But {4,6,8} is this horrible thing of length 116!

I've made some improvements to the code, including a function analyses that processes multiple sets of dice and then reports concisely on them all. Here's how it currently stands:
def analyse(dice, maxbits=100000, maxiters=100000, minbits=1000, miniters=1000):
    bits = minbits
    while bits <= maxbits:
        print(f"Trying {bits} bits, up to {maxiters} iterations.")
        mp.prec = bits
        prev,nits = 0,0
        dseq = []
        tol = mpmath.mpf(0.5)**(bits-10)
        nconv = 0
        for (prob,die) in itertools.islice(gend(dice), maxiters):
            if abs(prob-prev) <= tol and nits >= miniters:
                nconv += 1
                if nconv > 2*max(dice): break
            else: nconv = 0
            dseq.append(die)
            prev = prob
            nits += 1
        if nconv <= 2*max(dice):
            print("Not converged; giving up; try again with larger maxiters.")
            return None
        maxcoeff=2**(bits//6)
        tol=mpmath.mpf(0.5)**int(bits*0.85)
        print(f"Converged after {nits} iters; invoking findpoly with maxcoeff~=2^{mpmath.mag(maxcoeff)}, tol~=2^{mpmath.mag(tol)}.")
        expr = mpmath.findpoly(prob, maxcoeff=maxcoeff, tol=tol, maxsteps=maxbits)
        if not expr:
            if bits >= maxbits:
                print("No rational found; try again with larger maxbits?")
                return None
            print(f"No rational found with {bits} bits; trying with more.")
            bits = min(round(1.5*bits), maxbits)
            continue
        num = abs(expr[1])
        den = abs(expr[0])
        err = abs(mpmath.mpf(num)/mpmath.mpf(den)-prob)
        print(f"Likely rational value found: {num}/{den}")
        print(f"Error is about {mpmath.nstr(err,10)} (~{-mpmath.mag(err)} bits).")
        bits = round(1.5*bits)
        print(f"Double-checking with 50% more bits ({bits}).")
        mp.prec = bits
        miniters = nits
        prev,nits = 0,0
        tol = mpmath.mpf(0.5)**(bits-10)
        nconv = 0
        for (prob,die) in itertools.islice(gend(dice), round(1.25*maxiters)):
            if abs(prob-prev) <= tol and nits >= miniters:
                nconv += 1
                if nconv > 2*max(dice): break
            else: nconv = 0
            prev = prob
            nits += 1
        if nconv <= 2*max(dice):
            if bits >= maxbits:
                print("Failed to converge; giving up; try again with larger maxbits?")
                return None
            print("Failed to converge this time; continuing the search with more bits.")
            bits = min(round(1.2*bits), maxbits)
            continue
        err = abs(mpmath.mpf(num)/mpmath.mpf(den)-prob)
        print(f"Error is about {mpmath.nstr(err)}, 2^-bits~={mpmath.nstr(mpmath.mpf(0.5)**bits)}, num~={mpmath.nstr(mpmath.mpf(num))}.")
        if err >= mpmath.mpf(0.5)**int(bits*0.85):
            if bits >= maxbits:
                print("That's suspiciously large; giving up; try again with larger maxbits?")
                return None
            print("That's suspiciously large; continuing the search with more bits.")
            bits = round(1.2*bits)
            continue
        else:
            print("Seems OK.")
            break
    j = len(dseq)-2
    while j>20*max(dice) and dseq[j] == dseq[-1]: j -= 1
    j = int(0.8*j)
    dseq = dseq[:j]
    startpoint = len(dseq) // 10
    maxperiod = len(dseq) // 10
    period = None
    print(f"Attempting period-finding with {len(dseq)} values, start=maxperiod={maxperiod}.")
    for tl in range(1,maxperiod+1):
        tail = dseq[-tl:]
        reps = (len(dseq)-startpoint) // tl
        longtail = dseq[-(reps*tl):]
        if longtail == reps*tail:
            print("Period", tl)
            period = tl
            break
    else:
        print("No period found with this many iterations.")
        return (num,den,None,None,[],[])
    if period is not None:
        for i in range(len(dseq)-2*period):
            p = dseq[i:i+period]
            r = (len(dseq)-(i+period)) // period
            if dseq[i+period:i+period*(1+r)] == r*p:
                print("Repeating period starts at", i)
                print("Initial transient:", (dseq[:i] if i<100 else "long"))
                print("Repeating seq:", (' '.join(map(str,p)) if period<100 else "long"))
                print("Counts:", collections.Counter(p))
                return (num,den,period,i,dseq[:i],p)
                break
        return (num,den,period,None,[],tail)
def analyses(dices, **kwargs):
    results = []
    for dice in dices:
        print("Looking at", dice)
        results.append((dice, analyse(dice, **kwargs)))
    print("--------")
    for (dice, result) in results:
        if not result: print(f"{dice}: no rational found.")
        else:
            num, den, period, start, transient, p = result
            nlen = len(str(num))
            if nlen <= 80: rat = str(num) + "/" + str(den)
            else: rat = f"({len(str(num))} digits)"
            def h(n): return hex(n)[2:].upper()
            if p and max(dice)<16 and period<30: pstr = f"length {period} [{''.join(map(h,p))}]"
            elif p and period<15: pstr = f"length {period} [{' '.join(map(str,p))}]"
            else: pstr = f"length {period}"
            if not period: print(f"{dice}: {rat}, no periodicity found.")
            elif not start: print(f"{dice}: {rat}, {pstr}.")
            else: print(f"{dice}: {rat}, {pstr} starting {start}.")

(The gend function is unaltered.)
Warning: the analyse function now returns some information about what it found, and the printed representation of that can be long; you may want to be careful when using it interactively.
The approximations accepted by this code generally have only a few more bits error than the upper bound imposed by the working precision. Does this mean that it catches all bogus rationals? Alas, I am not sure it does. In the (5,6) case it gives us a rational number with 2135 digits in the numerator, and die-choices with a repeating period of length 123. This was found with 69195 bits of precision, and confirmed with 103792 bits, with an error of about 5x10^-31244; 2^-103792 is about 3x10^-31245. I reran with still higher precision, and got the same rational number with an error of about 5x10^-67731. Sounds good, no?
Well, remember that this case produced an earlier dubious rational approximation. I don't remember exactly what it was, but a dubious rational approximation (found by looking at the continued fraction for the 2135-digit rational, which has one coefficient that's 625 digits long) whose numerator with 84 digits; this approximation has error about 8x10^-793. That also sounds pretty good, no? Also suspicious: the 2135-digit approximation has a ton of factors of 10 in its denominator, and I'm pretty sure that an earlier dubious approximation I found also does, and that seems a bit fishy. (The continued-fraction-based one doesn't have very many, though.)
[UPDATE a bit later: I ran it again with more bits. Same result, good to about 10^-180000. And then more: good to about 10^-360000. And then even more: good to about 10^-900000. In both cases, it's out by only a modest number of units in the last place. Periodicity in the die-choices is consistent for at least about 3 million choices. I still think it's possible that all this is bogus, but if so then the precision needed to demonstrate that empirically may be excessive.]
All the other rationals and periods reported above have been checked with this version of the code, and I didn't spot any discrepancies.