In the 1973 MAA Annual High School Mathematics Examination (Part 1, Problem #2), students solved this classic spatial geometry puzzle:
"One thousand unit cubes are fastened together to form a large cube with edge length 10 units; this is painted and then separated into the original cubes. The number of these unit cubes which have at least one face painted is: (A) 600 (B) 520 (C) 488 (D) 480 (E) 400."
A large cube with edge length 10 is made of $10 \times 10 \times 10 = 1,000$ unit cubes.
When the entire exterior is painted:
The cubes that receive no paint at all are completely buried inside the interior.
Peeling off the 1-unit outer layer on all 6 sides leaves an unpainted interior cube with edge length:
$$10 - 2 = 8$$
The number of unpainted unit cubes in this inner core is:
$$8 \times 8 \times 8 = 8^3 = 512$$
Therefore, the number of unit cubes with at least one painted face is the total minus the unpainted core:
$$\text{Painted cubes} = 10^3 - 8^3 = 1000 - 512 = \mathbf{488}$$
We can also verify this by classifying the painted cubes by their position:
Face-interior cubes (1 painted face): $6$ faces, each having an $8 \times 8$ middle square $\implies 6 \times 64 = 384$ cubes.
Summing all categories:
$$8 + 96 + 384 = \mathbf{488}$$
In this lesson, we write a 3D loop in Lua to check boundary coordinates and count painted unit cubes!
Now you try. Replace ???? with N and run the code to verify that exactly 488 cubes have at least one painted face.
Type your code here:
See your results here:
Share your code
Show a friend, family member, or teacher what you've done!
Here is a share link to your code:
Need a hint?
💡 What now?
The code has ???? for the maximum z-coordinate boundary. For an $N \times N \times N$ cube, the outer boundary planes are $x = 1 \text{ or } N$, $y = 1 \text{ or } N$, and $z = 1 \text{ or } N$. Replace ???? with N (or 10) and click Run Code to count all cubes with painted faces!