Chapter 83
Work A Shift In The Riddler Gift Shop
Riddler Express
A bottle starts with whole vitamin tablets. Each morning you pull one item out at random: a whole tablet you cut in half, take one half, and return the other; a half-tablet you simply take. How many days, on average, until you first pull out a half-tablet? Extra credit: what if half-tablets are less likely to be drawn (being smaller)?
The Riddler, FiveThirtyEight, August 25, 2017(original post)
Solution
Every whole tablet you draw turns into one returned half, so the bottle always holds exactly pieces until the first half is pulled. On the day after you have drawn wholes, the bottle holds halves among those pieces, so the chance of pulling a half that day is . You reach day only by having drawn a whole on each earlier day, which happens with probability . Summing the survival probabilities gives the expected number of days, This is a Ramanujan-style sum, close to plus a small correction. If halves were less likely to be drawn (being smaller), each would linger longer in the bottle, so it would take even longer to pull the first one.
The computation
Sum the survival probabilities exactly, the product form of each term built up factor by factor.
from fractions import Fraction as F
n = 100
expected, term = F(0), F(1)
for m in range(n + 1):
expected += term
term *= F(n - m, n)
print(float(expected)) # 13.21
Riddler Classic
In the Riddler gift shop, we want to package four unit spheres in a regular tetrahedron. What is the smallest tetrahedron that holds all four spheres?
The Riddler, FiveThirtyEight, August 25, 2017(original post)
Solution
By symmetry, the optimal packing places each sphere snugly in one corner of the tetrahedron, with each sphere touching the three faces meeting at its corner. As we shrink the tetrahedron, all four spheres slide inward along their corner axes until they touch each other; the smallest tetrahedron is the one for which neighbouring spheres just touch.
Where does a corner sphere sit? A sphere of radius tangent to the three faces meeting at vertex sits on the line from to the centroid of the opposite face (the axis of three-fold symmetry of those three faces). Let be the angle between and any one of those three adjacent faces. The sphere’s center lies on at the distance from for which the perpendicular distance from to each adjacent face is , so
Computing . The angle is the angle between the axis and any adjacent face. Place the regular tetrahedron with vertices The side length is , the centroid is at the origin, and the axis points from in direction . The outward unit normal of face is as well (by symmetry, since the centroid is at the origin), and the outward unit normal of one of the three faces adjacent to , say , points roughly opposite to , specifically . The cosine of the angle between and this normal is So , and a unit sphere tucked in a corner of this scaled tetrahedron has its center at distance from the vertex along the axis.
Edge length. In the tetrahedron of side , the axis-distance scales by , so the corner sphere sits at distance from the vertex. But we need for the sphere to have radius , where now is the same in any regular tetrahedron (the angle is scale-invariant). So in fact for a unit sphere we need measured in the sphere’s own scale. Place coordinates so that each vertex sits at distance from the centroid (the centroid-to-vertex distance for a tetrahedron of side ). A corner sphere’s center lies on the vertex axis at distance from the vertex, so at distance from the centroid along the same axis.
The four sphere centers thus form a smaller regular tetrahedron, similar to the original and centered at the same point, with centroid-to-vertex distance . Its side length satisfies , that is, For the spheres to just touch, the sphere centers must be exactly apart, that is . Setting gives
The tetrahedron has side roughly times the radius of one of the four spheres, volume , against a total sphere volume of . The packing density is about , which is poor as packings go: tetrahedra are not friendly containers for spheres.
The computation
Place a regular tetrahedron of side in coordinates, compute the corner-sphere centers explicitly, verify each sphere has perpendicular distance to each of the three faces meeting at its corner, and confirm that all six pairs of sphere centers are exactly apart.
Set , vertices scaled accordingly.
For each vertex, walk along the axis toward the centroid until the perpendicular distance to an adjacent face is .
Check perpendicular distance to all three adjacent faces is at that point.
Check every pair of sphere centers is at distance .
import numpy as np
a = 2 + 2 * np.sqrt(6)
scale = a / (2 * np.sqrt(2))
v = scale * np.array([
[1, 1, 1], [1, -1, -1], [-1, 1, -1], [-1, -1, 1],
], dtype=float)
centroid = v.mean(axis=0)
def out_normal(p, q, r, inside):
n = np.cross(q - p, r - p); n /= np.linalg.norm(n)
if np.dot(n, (p + q + r) / 3 - inside) < 0:
n = -n
return n
faces = [(0,1,2),(0,1,3),(0,2,3),(1,2,3)]
def corner_sphere(i):
axis = centroid - v[i]; axis /= np.linalg.norm(axis)
adj = [f for f in faces if i in f][0]
n = out_normal(v[adj[0]], v[adj[1]], v[adj[2]], centroid)
d = -1 / np.dot(axis, n) # perp dist to face = 1
return v[i] + d * axis
centers = [corner_sphere(i) for i in range(4)]
# distances between centers
for i in range(4):
for j in range(i + 1, 4):
print(f"|S{i}S{j}| =", round(np.linalg.norm(centers[i] - centers[j]), 6))
# all should print 2.0
All six pairs of sphere centers come out at distance exactly , confirming the spheres are mutually tangent at the boxed edge length.