Books · The Fiddler: Solutions
Chapter 94
Can You Win at Non-Traditional Blackjack?
A deck has exactly ten cards, numbered through (the is always worth one). You shuffle and draw one card at a time, keeping a running total, and stop as soon as the total is at least . If it is exactly you win; if it overshoots, you bust. What is your probability of winning?
The Fiddler, Zach Wissner-Gross, May 24, 2024(original post)
Solution
Work forward through the draws. From a running total with a set of cards still in the deck, the next card is equally likely to be any of : if you win, if you bust, and otherwise you carry on from with that card removed. So the win probability obeys Unwinding this from the empty table over the full deck, , gives Landing exactly on is delicate: most paths either skid past it or stop just short.
The computation
The recurrence is exact, so evaluating it is the computation: memoise on the running total and the remaining cards, summing the three cases over the actual draws in rational arithmetic.
from fractions import Fraction as F
from functools import lru_cache
@lru_cache(maxsize=None)
def W(s, R): # R: frozenset of remaining cards
n = len(R); total = F(0)
for c in R:
t = s + c
if t == 21: total += F(1, n)
elif t < 21: total += F(1, n) * W(t, R - frozenset([c]))
# t > 21: bust, contributes 0
return total
print(W(0, frozenset(range(1, 11)))) # 7/40
Extra Credit
Now play it safe: the moment any remaining card could possibly bust you, you stop the round and reshuffle for a fresh one. On average, how many rounds until you finally win?
Solution
Under the cautious rule you draw only while every remaining card keeps you at or below, that is while ; the instant a bust becomes possible you stop and start a fresh round. A round is won if it reaches exactly before that safety margin runs out. The per-round win probability, computed by the same forward recurrence with the new stopping rule, is . Rounds are independent, so the number until a win is geometric, with mean Caution rarely pays: refusing ever to risk a bust means you almost always stop short of , and it takes about fifty fresh deals to finally land it.
The computation
The same recursion, now stopping the round as soon as any remaining card could bust, gives the per-round win probability and hence the expected number of rounds.
@lru_cache(maxsize=None)
def safe(s, R): # P(round won) playing risk-averse
if s == 21: return F(1)
if not R or s + max(R) > 21: return F(0) # any bust possible -> stop the round
n = len(R)
return sum(F(1, n) * safe(s + c, R - frozenset([c])) for c in R)
p = safe(0, frozenset(range(1, 11)))
print(p, 1 / p) # 13/630 630/13