Chapter 107
Can You Solve The Puzzle Of The Pirate Booty?
Ten perfectly rational pirate logicians, ranked from the captain on down, must split ten indivisible gold pieces. The captain proposes a division and everyone, captain included, votes. If at least half vote yes, it passes; otherwise the captain is thrown overboard, the next in rank becomes captain, and the process repeats. Each pirate votes by these rules, earlier ones overriding later: self-preservation (value your life above all), then greed (grab as much gold as possible), then bloodthirst (all else equal, vote to throw someone overboard). How is the gold divided? Extra credit: solve it for pirates and gold pieces.
The Riddler, FiveThirtyEight (Kyle Joecken)(original post)
Solution
No one walks the plank. The captain takes six and tosses a single coin to every second pirate beneath him: The one idea is that a pirate’s vote is bought not with generosity but with the threat of what he gets if the captain dies, so you must know the smaller games before you can price the larger one. Reason from the bottom up, naming the pirates (captain) down to .
Two pirates left. votes for his own plan, that is one of the two votes, which is at least half, so it passes. He keeps all ten and gets nothing.
Three. needs one more vote. faces nothing if dies, so a single coin wins him over. keeps nine, nothing, one.
Four. needs one extra vote and buys the cheapest pirate who would otherwise get zero, namely , for one coin.
The pattern is now fixed. A captain facing pirates needs votes: himself plus others. He buys exactly those pirates who would receive nothing if he were thrown overboard, one coin each, which is always a coin less than they’d lose. With all ten aboard, needs five votes, so he buys four: , the pirates left empty-handed in the nine-pirate game, for one coin apiece, and keeps the remaining six. Bloodthirst never bites because no pirate is ever left indifferent: each bribed pirate is strictly better off voting yes.
Extra credit. As long as the gold covers the bribes, that is , the same alternating pattern holds: the captain pays one coin to every second pirate down the chain and keeps for himself (possibly zero, but he keeps his life). Only when the gold runs short of the bribes the captain needs does blood finally get spilled.
The computation
Encode the backward induction. Knowing the division among pirates, the captain of buys the cheapest votes, one coin more than each target would get without him, until he has enough, and keeps the rest.
def divide(P, G):
res = {1: [G]} # one pirate keeps everything
for m in range(2, P + 1):
fallback = res[m - 1] # what pirates 2..m get if captain dies
need = (m + 1) // 2 # votes required (>= half, incl. captain)
alloc, spent = [0] * m, 0
# cheapest voters first: those who'd get least if the captain is thrown over
for j in sorted(range(1, m), key=lambda k: fallback[k - 1])[:need - 1]:
alloc[j] = fallback[j - 1] + 1 # one coin beats their fallback
spent += alloc[j]
alloc[0] = G - spent # captain keeps the rest
res[m] = alloc
return res[P]
print(divide(10, 10))
# [6, 0, 1, 0, 1, 0, 1, 0, 1, 0]