Chapter 103
Can You Solve This Napoleonic Puzzle?
Short but deadly. Complete the series: That is the whole puzzle.
The Riddler, FiveThirtyEight (Andy Laursen)(original post)
Solution
The trap is reading the entries as ordinary base-ten numbers. They are not numbers at all but digit-strings, and every one of them spells the same value, fifteen, in a different base. The list is just written in base , then base , then , and so on downward.
The first entry makes the pattern visible. In base the value fifteen is one fifteen and no units, written 10. Drop the base by one to : now fifteen is one fourteen and one unit, 11. Each step down adds one to the units digit, until the units would overflow. At base a second place is forced: , then , , and in base . The printed list stops there, so the next two terms are fifteen in base and base : The missing terms are The deadly brevity is the point: with no operations to reverse-engineer, the only foothold is to suspect that the digits are speaking in shifting bases.
The computation
Write fifteen out in each base from down to and read off the sequence; the two terms past base are the answer.
def in_base(n, b):
digits = []
while n:
digits.append(str(n % b))
n //= b
return ''.join(reversed(digits)) or '0'
print([in_base(15, b) for b in range(15, 1, -1)])
# ['10', '11', '12', '13', '14', '15', '16', '17',
# '21', '23', '30', '33', '120', '1111']