Lesson goal: The painted cube faces

Previous: Drawing polylines in 3D | Home | Next: Tetrahedron inscribed in a cube

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:
  • Corner cubes (3 painted faces): Exactly $8$ corners $\implies 8$ cubes.
  • Edge cubes (2 painted faces): $12$ edges, each having $10 - 2 = 8$ middle cubes $\implies 12 \times 8 = 96$ cubes.
  • 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: