Chapter 118
The Particular Mathematician’s Cake
A mathematician wants a three-layer cake that fits under a hollow glass cone on his desk. Each layer must have straight vertical sides, and together they must fill as much of the cone’s volume as possible. In terms of the cone’s height, how thick should the three layers be, and what fraction of the cone does the best cake fill?
The Riddler, FiveThirtyEight(original post)
Solution
A vertical-sided layer is a cylinder, and a cylinder fits under the cone only if it is no wider than the cone at the layer’s top, its narrowest point. That one constraint is the whole problem: each layer’s radius is decided by where its top sits, and we choose the tops to maximise total volume.
Measure heights as fractions of the cone’s height , with the base at and the apex at . At fractional height the cone’s radius has shrunk to a fraction of the base radius, so its cross-sectional area is times the base area . Let the layer tops sit at heights . Layer runs from to (with ), is a cylinder of area and height , and the cone’s own volume is . The fraction filled is
Maximise by setting each partial derivative to zero. Writing for the cone’s remaining fraction at the top of layer (and ), the layer heights are , and the conditions tidy into a recurrence plus a top rule: The top rule says the highest layer should be exactly half as tall as the cone’s remaining height above it; the recurrence ties each layer back to the one below. Solving the three relations with gives , and then the tier heights, from bottom to top, which fill about of the cone. The layers thicken as they rise, because higher up the cone narrows faster, so a taller slice there costs less lost width.
Extra Credit
What if he had asked for an -layer cake?
Solution
Nothing in the setup used the number three. For layers the same conditions hold all the way up: This is a two-point problem: anchor at the base, fix the top ratio, and the single free starting step is tuned until the top rule is met. Each extra layer hugs the cone more closely, so the filled fraction climbs steadily toward as grows. Boxing a single formula is not the point here; the value for any comes from solving the recurrence, which the computation does.
The computation
Encode the volume fraction directly and maximise it. For three layers, confirm the boxed tiers and both by evaluating the closed form and by a brute-force search over all valid tops. For the extra credit, optimise the same fraction for several and watch it rise.
import numpy as np
from scipy.optimize import minimize
def fill_fraction(cuts): # cuts = layer tops s_1..s_N
s = np.concatenate(([0.0], np.sort(np.clip(cuts, 0, 1))))
return 3 * sum((s[i] - s[i-1]) * (1 - s[i])**2 for i in range(1, len(s)))
# three layers: closed form matches the boxed tiers and 70.2%
a, b, c = 205/1263, 230/1263, 276/1263
print("tiers :", [round(x, 4) for x in (a, b, c)])
print("closed P:", round(fill_fraction([a, a+b, a+b+c]), 4))
rng = np.random.default_rng(0)
for N in (1, 2, 3, 4, 6, 10):
best = 0.0
for _ in range(40): # multi-start for the global max
x0 = np.sort(rng.uniform(0, 1, N))
r = minimize(lambda c: -fill_fraction(c), x0,
method="Nelder-Mead",
options={"xatol": 1e-9, "fatol": 1e-12})
best = max(best, -r.fun)
print(f"N={N:2d}: best fill = {best:.4f}")
# tiers : [0.1623, 0.1821, 0.2185]
# closed P: 0.7017
# N= 1: best fill = 0.4444
# N= 2: best fill = 0.6125
# N= 3: best fill = 0.7017
# N= 4: best fill = 0.7573
# N= 6: best fill = 0.8229
# N=10: best fill = 0.8848