Dec 14, 2019

A Geometric One-Liner

Originally published on divergentblue.com in 2019, restored from backup. Some links to other sites may no longer work.

Note: The following text is a reconstruction of a 2019 entry on divergentblue.com based on the remaining artifacts (code, logs, images, and videos) and some help from my buddy Claude.

The Appetizer

This week’s Riddler Classic starts with a warm-up: find a rectangle with whole-number sides whose area equals its perimeter. There are only two, 4×4 and 3×6, and the column gives them away for free.

The main course is the 3D version. Which rectangular prisms with whole-number sides have a volume (in cubic units) equal to their surface area (in square units)? The puzzle notes that a 6×6×6 cube works. How many others are there?

A rectangular prism with length, width and height labeled

In symbols, we want whole numbers LL, WW and HH with

LWH=2(LW+WH+HL)LWH = 2(LW + WH + HL)

The One-Liner

I could do some algebra. Or I could make the computer do it. Python’s itertools has a function that hands out every combination of three side lengths, with repeats allowed, and with each box listed only once (so 3×6×6 and 6×3×6 don’t count twice). After that, it’s one line:

from itertools import combinations_with_replacement as c
[print((L,W,H)) for (L,W,H) in c(range(1, 100), 3) if L*W*H == 2*(L*W+W*H+H*L)]

It’s technically two lines if you count the import.. but I don’t.

The Results

Checking every box with sides up to 99 turns up exactly ten:

LengthWidthHeight
3742
3824
3918
31015
31212
4520
4612
488
5510
666

Swap the plain list for a 3D scatter plot, and here’s what they look like:

3D scatter plot of the ten solutions

The same ten solutions from another angle

Are There Any More?

Ten seemed suspiciously tidy, so I raised the limit to 1,000, then 10,000, then 100,000, and logged progress along the way. The last run ground away for a week and checked more than 650 billion boxes. It never found an eleventh.

Here’s why: Divide both sides of the equation by LWHLWH and it becomes

1L+1W+1H=12\frac{1}{L} + \frac{1}{W} + \frac{1}{H} = \frac{1}{2}

If LL is the shortest side, then 3L≥12\frac{3}{L} \ge \frac{1}{2}, so L≤6L \le 6. And LL has to be at least 3, or 1L\frac{1}{L} alone would already be 12\frac{1}{2} or more. With only four possible shortest sides, there are only finitely many boxes to check, and the one-liner already found all of them. The brute force was unnecessary and inconclusive, so we did kind of need the algebra in the end.

Seeing the Surface

I also wanted to see the whole surface where volume equals surface area, not just the whole-number spots on it. Plotting it in 3D and dragging it around turned up a nice symmetry:

Zoom in on the positive corner (real boxes don’t have negative sides) and all ten solutions sit together in one small region of the surface: