Chapter 33
How Many Ways Can You Raid The Candy Shop?
Riddler Express
Using exactly three nines and the operations add, subtract, multiply, divide, exponentiate, or write side-by-side, the biggest number is . Now: what is the biggest number you can make with exactly four threes?
Solution
Repeated exponentiation dwarfs everything else, so the answer is a power tower, and the only question is how to spend four threes to make the tower’s top as large as possible. Building straight up gives , whose top exponent is . But writing two of the threes side by side as and lifting it one level gives , whose top exponent is , larger by three orders of magnitude. Since the whole number is raised to that top, the bigger top wins: Other arrangements (, , ) put far smaller numbers in the exponent and do not come close.
The computation
These numbers are too large to write out, so compare them by iterated logarithm: each is raised to some exponent , and ranks them.
import math
cands = {"3^(3^33)": 3**33, "3^(3^(3^3))": 3**27,
"3^(33^3)": 33**3, "(3^3)^33": 99, "33^(3^3)": None}
for name, E in cands.items():
if E: # the number is 3**E
print(name, round(math.log10(E * math.log10(3)), 4))
# 3^(3^33) has the largest iterated logarithm -> the biggest number
Riddler Classic
Three kinds of candy are for sale. You want to buy at least one candy and at most 100, with no constraint on how many of each. How many distinct ways are there to make your purchase?
Solution
A purchase is a triple of nonnegative counts with . Count the triples with by adding a slack variable so that ; the number of nonnegative solutions is the stars-and-bars count . Removing the single empty purchase () leaves
The computation
Evaluate the closed form, and cross-check by summing the triangular counts for each total from to .
from math import comb
print(comb(103, 3) - 1) # 176850
print(sum(comb(n + 2, 2) for n in range(1, 101))) # 176850