Skip to content
Vamshi Jandhyala

Books · The Riddler

Chapter 155

Ballots, Primaries, and the Spy in Riddler Nation

The Riddler for July 21, 2017. The Express is a tidy combinatorial count: 1111 candidates for 33 at-large seats with up-to-33 votes per ballot, asking how many distinct ballots and how many distinct top-66 outcomes are possible. The Classic is the third war of Riddler Nation, now with a spy: knowing your enemy’s distribution of 100100 soldiers across 1010 castles worth 1,2,,101, 2, \ldots, 10 points, what is the minimum army size you can guarantee a victory with?

Riddler Express

In a primary, 1111 candidates compete for 33 at-large seats on a City Commission. Each voter may vote for at most 33 candidates (so a ballot may name 00, 11, 22, or 33 candidates, but never the same candidate twice). The election reduces the field of candidates from 1111 to 66 for the general. How many distinct legal ballots are possible? How many distinct outcomes are there for who advances to November’s general election (ignoring ties)?

The Riddler, FiveThirtyEight, July 21, 2017(original post)

Solution

Ballot count. A ballot is an unordered subset of size 00, 11, 22, or 33 drawn from 1111 distinct candidates (the order of marks does not matter, since each named candidate gets one tick). The count is the sum of binomial coefficients: Nballots=(110)+(111)+(112)+(113)=1+11+55+165  =  232.\begin{aligned} N_{\text{ballots}} &= \binom{11}{0} + \binom{11}{1} + \binom{11}{2} + \binom{11}{3}\\ &= 1 + 11 + 55 + 165 \;=\; 232. \end{aligned}

Outcome count. The primary advances exactly 66 candidates to the general, chosen from 1111. With ties excluded, the outcome is simply the set of 66 advancing candidates, which is Noutcomes  =  (116)  =  462.N_{\text{outcomes}} \;=\; \binom{11}{6} \;=\; 462.

Nballots  =  232,Noutcomes  =  462.\boxed{\,N_{\text{ballots}} \;=\; 232,\qquad N_{\text{outcomes}} \;=\; 462.\,}

The computation

Enumerate the ballots and outcomes directly. For ballots, iterate over every subset of the 1111 candidates whose size is at most 33. For outcomes, iterate over every subset of size exactly 66.

from itertools import combinations

CANDIDATES = list(range(11))

ballots = []
for k in range(0, 4):
    ballots.extend(combinations(CANDIDATES, k))
outcomes = list(combinations(CANDIDATES, 6))

print(f"distinct ballots = {len(ballots)}")
print(f"distinct outcomes = {len(outcomes)}")
# distinct ballots = 232
# distinct outcomes = 462

The enumerated counts reproduce the boxed values exactly.

Riddler Classic

Two warlords compete to take the most points by conquering 1010 castles worth 1,2,3,,9,101, 2, 3, \ldots, 9, 10 victory points. Each warlord distributes troops across the castles. The warlord with strictly more troops at a castle conquers it and earns its points; ties split the points evenly. The whole-tournament winner is whoever earns the most points overall. Your enemy has 100100 soldiers. You have a spy: you know your enemy’s full distribution before you commit. But your army is smaller. What is the smallest kk such that, no matter the enemy’s distribution of 100100, you can pick a distribution of kk soldiers that wins?

The Riddler, FiveThirtyEight, July 21, 2017(original post)

Solution

The total point pool is 1+2++10=551 + 2 + \cdots + 10 = 55. To guarantee a strict win you need at least 2828 points (since 2727 leaves the enemy 2828).

Best response with a spy. Knowing the enemy’s distribution (x1,,x10)(x_1, \ldots, x_{10}), your best response is to identify a subset S{1,,10}S \subseteq \{1, \ldots, 10\} of castles whose point sum is at least 2828 and whose total “conquest cost” is minimised; you spend xi+1x_i + 1 soldiers at each castle iSi \in S (one more than the enemy posts) and 00 at the rest. (Tying with the enemy splits points, which we account for separately below; but the cleanest strict-majority argument uses xi+1x_i + 1.) The required force is c(x,S)  =  iS(xi+1)  =  S  +  iSxi.c(\mathbf{x}, S) \;=\; \sum_{i \in S} (x_i + 1) \;=\; |S| \;+\; \sum_{i \in S} x_i.

The enemy’s worst distribution. The enemy will choose x\mathbf{x} to make even your best response expensive. They want every castle to be “equally inefficient” in points per soldier required. If the cost-per-point at castle ii is (xi+1)/i(x_i + 1) / i, the enemy equalises these ratios: xi+1i  =  constant  =  ρxi+1  =  ρi.\frac{x_i + 1}{i} \;=\; \text{constant} \;=\; \rho \quad \Longrightarrow \quad x_i + 1 \;=\; \rho\, i. The enemy’s troop budget is fixed at 100100: i=110xi  =  i=110(ρi1)  =  55ρ10  =  100ρ=2.\sum_{i = 1}^{10} x_i \;=\; \sum_{i = 1}^{10} (\rho\, i - 1) \;=\; 55 \rho - 10 \;=\; 100 \quad \Longrightarrow \quad \rho = 2. So the enemy plays xi=2i1x_i = 2i - 1: that is 1,3,5,7,9,11,13,15,17,191, 3, 5, 7, 9, 11, 13, 15, 17, 19, summing to 100100. Every castle then costs exactly two soldiers per victory point.

Your minimal force. To gather at least 2828 points at a uniform cost of 22 per point, you need at least 5656 soldiers. Concretely, conquer castles 11 through 77 with 2,4,6,8,10,12,142, 4, 6, 8, 10, 12, 14 soldiers (5656 in total) to claim 1+2+3+4+5+6+7=281 + 2 + 3 + 4 + 5 + 6 + 7 = 28 points; the enemy keeps castles 88, 99, 1010 with 15+17+19=5115 + 17 + 19 = 51 soldiers, scoring only 8+9+10=278 + 9 + 10 = 27 points. A second optimal response is to attack castles 11, 88, 99, 1010 with 2+16+18+20=562 + 16 + 18 + 20 = 56 soldiers, again reaching 2828.

Sufficiency for all x\mathbf{x}. For any enemy distribution (x1,,x10)(x_1, \ldots, x_{10}) summing to 100100, your best-response cost is at most 5656. The reason: pick the subset SS^* that maximises iSi\sum_{i \in S^*} i subject to S+iSxi56|S^*| + \sum_{i \in S^*} x_i \le 56. The enemy’s choice equalises the cost-per-point at exactly 22, hence achieves the maximum of the minmax. Any deviation by the enemy from 2i12i - 1 creates at least one castle where the cost-per-point is less than 22, giving you a cheaper subset.

So the value of the spy is exactly 56100=4456 - 100 = -44 relative to a fair fight (you can shed 4444 of your 100100 original soldiers and still guarantee a win): k  =  56.\boxed{\,k \;=\; 56.\,}

The computation

Encode the problem directly. Set the worst-case enemy distribution x=(1,3,5,,19)\mathbf{x} = (1, 3, 5, \ldots, 19). Brute-force the minimum-cost subset of castles whose total point sum reaches at least 2828. Confirm the answer is 5656. As a separate check, run many random enemy distributions and confirm 5656 soldiers always suffices and 5555 sometimes does not.

from itertools import combinations
import random

def best_response_cost(enemy, target=28):
    """Min cost to claim >= target points; cost at castle i is enemy[i]+1."""
    n = len(enemy)
    best = None
    for size in range(1, n + 1):
        for S in combinations(range(n), size):
            if sum(i + 1 for i in S) >= target:
                cost = sum(enemy[i] + 1 for i in S)
                if best is None or cost < best:
                    best = cost
    return best

enemy_worst = [2*i - 1 for i in range(1, 11)]   # 1,3,5,...,19
print(f"worst-case enemy {enemy_worst}, sum {sum(enemy_worst)}")
print(f"best-response cost = {best_response_cost(enemy_worst)}")

# Sample random enemies; confirm 56 always suffices
rng = random.Random(0)
def random_enemy(rng):
    cuts = sorted(rng.sample(range(1, 110), 9))
    parts = [cuts[0]] + [cuts[i+1] - cuts[i] for i in range(8)] + [110 - cuts[8]]
    return [p - 1 for p in parts]   # shifts so sum = 100, non-negative

max_cost = 0
for _ in range(20_000):
    e = random_enemy(rng)
    if sum(e) != 100: continue
    c = best_response_cost(e)
    if c > max_cost: max_cost = c
print(f"max best-response cost over 20,000 random enemies = {max_cost}")
# worst-case enemy [1, 3, 5, 7, 9, 11, 13, 15, 17, 19], sum 100
# best-response cost = 56
# max best-response cost over 20,000 random enemies = 48

Brute force on the canonical worst-case distribution returns exactly 5656. Uniform-random sampling of partitions of 100100 rarely lands near (1,3,5,,19)(1, 3, 5, \ldots, 19), so the sampled maximum sits well below 5656; that is consistent with the worst case being a sharp ridge in the distribution space, not a typical one. The spy is worth 4444 soldiers.