Skip to content
Vamshi Jandhyala

Books · The Riddler

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 HH, with the base at 00 and the apex at 11. At fractional height ss the cone’s radius has shrunk to a fraction (1s)(1-s) of the base radius, so its cross-sectional area is (1s)2(1-s)^2 times the base area ABA_B. Let the layer tops sit at heights s1s2s3s_1 \le s_2 \le s_3. Layer ii runs from si1s_{i-1} to sis_i (with s0=0s_0=0), is a cylinder of area (1si)2AB(1-s_i)^2 A_B and height (sisi1)H(s_i-s_{i-1})H, and the cone’s own volume is ABH/3A_B H/3. The fraction filled is P=VcakeVcone=3i=13(sisi1)(1si)2.P = \frac{V_{\text{cake}}}{V_{\text{cone}}} = 3\sum_{i=1}^{3} (s_i - s_{i-1})(1-s_i)^2 .

Maximise by setting each partial derivative to zero. Writing ri=1sir_i = 1-s_i for the cone’s remaining fraction at the top of layer ii (and r0=1r_0=1), the layer heights are sisi1=ri1ris_i-s_{i-1} = r_{i-1}-r_i, and the conditions tidy into a recurrence plus a top rule: ri+12=ri(3ri2ri1)(i=1,2),r2=32r3.r_{i+1}^2 = r_i\,(3r_i - 2r_{i-1}) \quad (i=1,2), \qquad r_2 = \tfrac32\, r_3 . 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 r0=1r_0=1 gives r3=184/421r_3 = 184/421, and then the tier heights, from bottom to top,   a=2051263,b=2301263,c=2761263      (0.162, 0.182, 0.219)H,\boxed{\;a = \tfrac{205}{1263},\quad b = \tfrac{230}{1263},\quad c = \tfrac{276}{1263}\;} \;\approx\; (0.162,\ 0.182,\ 0.219)\,H, which fill P=3(ar12+br22+cr32)0.702,P = 3\bigl(a\,r_1^2 + b\,r_2^2 + c\,r_3^2\bigr) \approx \boxed{0.702}, about 70.2%70.2\% 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 NN-layer cake?

Solution

Nothing in the setup used the number three. For NN layers the same conditions hold all the way up: ri+12=ri(3ri2ri1)(1iN1),r0=1,rN1=32rN.\begin{gathered} r_{i+1}^2 = r_i\,(3r_i - 2r_{i-1}) \quad (1 \le i \le N-1),\\ r_0 = 1, \qquad r_{N-1} = \tfrac32\, r_N . \end{gathered} This is a two-point problem: anchor r0=1r_0=1 at the base, fix the top ratio, and the single free starting step r1r_1 is tuned until the top rule is met. Each extra layer hugs the cone more closely, so the filled fraction climbs steadily toward 100%100\% as NN grows. Boxing a single formula is not the point here; the value for any NN 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 70.2%70.2\% 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 NN 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