Skip to content
Vamshi Jandhyala

Books · The Fiddler: Solutions

Chapter 76

Did xkcd Get Its Math Right?

From Seth Cohen comes a puzzle that fact-checks a webcomic. Two quantities are in play. Let pp be the probability that, drawing two arrows at random from a quiver of ten (of which five are cursed), neither drawn arrow is cursed. Let qq be the probability that rolling three six-sided dice and one four-sided die gives a total of at least 1616.

Does pp equal qq? If so, what is their common value? If not, what is each?

The Fiddler, Zach Wissner-Gross, November 29, 2024(original post)

Solution

The arrows come first. Two of the ten are drawn, and the favourable draws are the pairs taken from the five uncursed arrows: p=(52)(102)=1045=29.p=\frac{\binom{5}{2}}{\binom{10}{2}}=\frac{10}{45}=\frac29 . For the dice, three d6d6 and one d4d4 give 634=8646^3\cdot4=864 equally likely outcomes. Convolving the distribution of 3d63d6 with the d4d4 and counting those at 1616 or more gives exactly 192192, so q=192864=29.q=\frac{192}{864}=\frac29 . They match: p=q=290.2222.p=q=\boxed{\tfrac29}\approx0.2222 . The comic’s two side-by-side mechanisms really do share the same probability.

The computation

Count both directly: the uncursed pairs over all pairs for pp, and the 3d6+d43d6+d4 outcomes reaching 1616 for qq.

from fractions import Fraction as F
from math import comb
from collections import Counter
p = F(comb(5, 2), comb(10, 2))                 # uncursed pairs / all pairs
d3 = Counter()
for a in range(1, 7):
    for b in range(1, 7):
        for c in range(1, 7): d3[a + b + c] += 1
ge = tot = 0
for s, w in d3.items():
    for d in range(1, 5):
        tot += w
        if s + d >= 16: ge += w
q = F(ge, tot)
print(p, q, p == q, f"{ge}/{tot}")            # 2/9 2/9 True 192/864

Extra Credit

Using the same probability p=29p=\tfrac{2}{9}, how many ways can you simulate it by rolling up to four dice from a standard set (d4,d6,d8,d10,d12,d20d4,d6,d8,d10,d12,d20) and asking for a sum at or above some threshold, and what are they?

Solution

Searching every multiset of one to four dice and every threshold, exactly three combinations reproduce p=29p=\tfrac29: 3d6+d4: sum16,2d6+d8+d10: sum21,d10+2d12+d20: sum36.\begin{aligned} 3d6+d4 &:\ \text{sum}\ge16,\\ 2d6+d8+d10 &:\ \text{sum}\ge21,\\ d10+2d12+d20 &:\ \text{sum}\ge36. \end{aligned} The first is the comic’s own; the other two are alternative four-die machines for the same 29\tfrac29.

The computation

Build each candidate’s sum distribution by convolution, then test every threshold against the target probability.

from itertools import combinations_with_replacement as cwr
DICE = {'d4': 4, 'd6': 6, 'd8': 8, 'd10': 10, 'd12': 12, 'd20': 20}
def dist(dl):
    d = Counter({0: 1})
    for nm in dl:
        nd = Counter()
        for s, c in d.items():
            for f in range(1, DICE[nm] + 1): nd[s + f] += c
        d = nd
    return d
target = F(2, 9); ways = []
for k in range(1, 5):
    for combo in cwr(DICE, k):
        d = dist(combo); tot = sum(d.values())
        for T in range(min(d) + 1, max(d) + 1):
            if F(sum(c for s, c in d.items() if s >= T), tot) == target:
                ways.append(('+'.join(combo), T))
for combo, T in ways: print(combo, ">=", T)      # the three machines above