# Coloring the faces of n^3 unit cubes s.t., for each color j between 1 and n, the cubes can be arranged to form nxnxn cube with j-colored outer faces

I encountered the following problem in Paul Zeitz's The Art and Craft of Problem Solving (problem 2.4.16 on page 56 of third edition):

Is it possible to color the faces of 27 identical $$1 \times 1 \times 1$$ cubes, using the colors red, white, and blue, so that one can arrange them to form a $$3 \times 3 \times 3$$ cube with all exterior faces red; and then rearrange them to form a $$3 \times 3 \times 3$$ cube with all exterior faces blue; and finally, rearrange them to form a $$3 \times 3 \times 3$$ cube with all exterior faces white? What about the general case ($$n$$ colors and an $$n \times n \times n$$ cube)?

I was able to come up with, through logical trial-and-error, the coloring that works for $$n=3$$, so I think the answer is 'yes'. Indeed, I verified my answer, as there is another post on this site concerning the $$n=3$$ case.

Unfortunately, I am extremely stuck on how to generalize this to the $$n$$ color case. Any hints or advice would be greatly appreciated. Thank you!

• @CalvinLin We want to have $n$ colors for the $n \times n \times n$ cube, not $3$ colors. This exactly uses up all the faces of the small cubes. Commented May 31, 2023 at 16:09
• @MishaLavrov Ah yes, I missed that. Hm ... Commented May 31, 2023 at 16:11

Here is a solution which does not require case-splitting based on $$n$$. This solution is an adaptation of Jaap's clever solution to the $$3\times 3\times 3$$ problem to the $$n\times n\times n$$ version.

Start with $$n^3$$ uncolored cubes. Label each cube with a distinct ordered triple, $$(x,y,z)$$, where $$x,y,z\in \{0,1,\dots,n-1\}$$. For the cube with label $$(x,y,z)$$,

• color the top face with color number $$x$$, and the bottom face with color number $$x+1$$, where addition is modulo $$n$$,

• color the left face with color number $$y$$, and the right face with color number $$y+1$$,

• color the front face with color number $$z$$, and the back face with color number $$z+1$$.

Equivalently, the process can be described as follows.

• Arrange the $$n^3$$ uncolored cubes into a big cube, and paint all outside faces the first color.

• Take the top layer, and move it to the bottom, without rotating.
Take the leftmost layer, and move it to the right, without rotating.
Take the frontmost layer, and move it to the back, without rotating.
Now, all outside faces are uncolored. Paint all outside faces with the next unused color.

• Repeat the previous bullet $$n-2$$ times.

The latter description has the benefit of describing how to arrange all the little cubes into a cube so that the outside is monochrome in each of the $$n$$ colors.

• Very nice coloring! I didn't think there was such a simple description of it. Commented May 31, 2023 at 17:34
• Thank you! If you don't mind me asking — how on earth did you think of this argument? I'm trying to improve my problem-solving skills (hence why I am working through this book), but I feel like no amount of investigation would have led me to consider this way of coloring, but it just ends up resolving the problem instantly. Commented May 31, 2023 at 22:38
• @vietajumping I am pretty sure I saw this argument somewhere else. I should have clarified this wasn't my original idea, but I forgot where I heard this so I cannot cite my source. Commented May 31, 2023 at 23:17
• @vietajumping Wait a second, I know exactly where I got this idea from! It was the Jaap's answer to the question that you linked. Commented Jun 1, 2023 at 17:21
• Thanks! But that one doesn't mention the coloring with the mod n — where did you get that from? Commented Jun 1, 2023 at 22:06

There are $$6n^2$$ small squares on the outside of an $$n \times n\times n$$ cube; with $$n$$ colors, that's $$6n^3$$ small squares, which exactly covers all the faces of $$n^3$$ small cubes. So we'll have to color every face of every small cube.

Each color needs three types of small cubes: $$8$$ cubes that go in the corners, $$12(n-2)$$ cubes that go on the edges, and $$6(n-2)^2$$ cubes that go in the middle of the faces. The easiest generalization starts with $$n \ge 6$$; in this case, we can deal with each type separately:

1. We want a total of $$4n$$ cubes colored with three faces of one color, and three of another, in any symmetric way such that each color is used on a total of $$8$$ of them.
2. We want a total of $$4n(n-2)$$ cubes colored with two faces of each of three colors, in any symmetric way such that each color is used on a total of $$12(n-2)$$ of them.
3. We want a total of $$n(n-2)^2$$ cubes colored with one face of each of six colors, in any symmetric way such that each color is used on a total of $$6(n-2)^2$$ of them.

I will leave the details unspecified, but it should not be hard to fill them in. However, step 3 clearly does not work for $$n < 6$$.

The case $$n=3$$ has already been done, and some similar approach can also finish $$n=4$$ and $$n=5$$.

• Not quite. We don't have to pair the edge cubes as edge-edge-edge. We could use corner-edge-side cubes, like in the $n=3$ case. Likewise, we use corner-corner and corner-edge-side cubes to get the mix. In fact, for $n=3$, there is a unique coloring (up to standard isomorphism). Commented May 31, 2023 at 16:28
• This makes sense for the $n \geq 6$ case, thanks! Commented May 31, 2023 at 16:44
• @CalvinLin I agree that we don't have to do that, but for $n\ge 6$, we can do that, and I felt that this was the simplest solution to describe. Commented May 31, 2023 at 17:47
• Yup, lots of approaches. Mine does seem tedious esp when compared to yours and Mike, though I could show that we don't need to use the 6-surfaces cube which both of you needed. Commented May 31, 2023 at 19:46

By a double-counting argument on the individual surfaces, we need to use each of them exactly once when forming the $$n$$ cubes of a given color.

Think about the individual faces and their pairings that you need. For a color $$A$$, we want:

• 8 corner cubes with $$A-A-A$$ meeting at a corner
• $$12(n-2)$$ edge cubes with $$A-A$$ meeting at a side
• $$6(n-2)^2$$ surface cubes with $$A$$ on a side.
• $$(n-2)^3$$ internal cubes that we don't care about the colors (and from above cannot have color $$A$$ on them).

If we have such cubes, then we obviously can put together the cube of color $$A$$. Hence, the question boils down to if we can color the $$n^3$$ cubes in such a manner.

Let's investigate how to form a unit cube: To form the 6 sides of a cube, we could pair up distinct colors in the following ways:

• 2 corners: $$A-A-A$$ and $$B-B-B$$
• 3 edges: $$A-A, B-B, C-C$$
• 1 corner, 1 edge, 1 surface: $$A-A-A, B-B, C$$
• 2 edges, 2 surfaces: $$A-A, B-B, C, D$$
• 1 edge, 4 surfaces: $$A-A, B, C, D, E$$
• 6 surfaces: $$A, B, C, D, E, F$$

Note that for $$n = 3, 4$$, we can't use the cubes with more than $$n$$ colors.

Let's consider $$n=2$$.
We want 8 corner cubes for individual colors, and we can make each cube a "2 corner" cube hence we are done.

Let's consider $$n=2$$.
We know there is a solution of:

• 3 of 2 corners. For a given color $$A$$, this creates 2 corner cubes and 1 internal cube.
• 18 of 1 corner, 1 edge, 1 surface. For a given color $$A$$, this creates 6 corner cubes, 6 edge cubes, and 6 surface cubes.
• 6 of 3 edges. For a given color $$A$$, this creates 6 edge cubes.

How can we find this solution on 27 cubes?
Let's make a simplifying (but unnecessary) assumption that the cubes have cyclic symmetry in colors. This means that for each cube type, we have a multiple of 3 of them, corresponding to cycling though the 3 colors.
If we use $$3a$$ of 2 corners, $$3b$$ of 1 corner, 1 edge, 1 surface, and $$3c$$ of 3 edges, then for a given color $$A$$, we will have

• Corners: $$2a + b = 8$$
• Edges: $$b + 3c = 12$$
• Surfaces: $$b = 6$$
• Internal: $$a = 1$$
• Total cubes: $$a+b+c = 9$$ This yields the unique consistent system $$a = 1, b = 6, c = 2$$, which matches the above.

In fact, this is the unique solution (up to various isomorphisms of coloring these cubes), even if we relax the unnecessary assumption.

Let's deal with $$n=4$$
Again we make the simplifying assumption that the cubes have cyclic symmetry in colors. If we use $$4a$$ of 2 corners, $$4b$$ of 1 corner, 1 edge, 1 surface, and $$4c$$ of 3 edges, $$4d$$ of 2 edges, 2 surfaces then for a given color $$A$$, we will have

• Corners: $$2a + b = 8$$
• Edges: $$b + 3c +2d = 24$$
• Surfaces: $$b +2d = 24$$
• Internal: $$2a + b + c = 8$$
• Total cubes: $$a+b+c+d = 16$$

This yields multiple integer solutions. EG If we set $$c = 0$$, we have $$0 \leq a \leq 4, b = 8 - 2a, d = a+8$$.

Let's deal with $$n \geq 5$$

Again we make the simplifying assumption that the cubes have cyclic symmetry in colors. If we use $$na$$ of 2 corners, $$nb$$ of 1 corner, 1 edge, 1 surface, and $$nc$$ of 3 edges, $$nd$$ of 2 edges, 2 surfaces, and $$ne$$ of 1 edge, 4 surfaces, then for a given color $$A$$, we will have

• Corners: $$2a + b = 8$$
• Edges: $$b + 3c +2d+e = 12(n-2)$$
• Surfaces: $$b +2d+4e = 6(n-2)^2$$
• Internal: $$(n-2)a + (n-3)b + (n-3)c + (n-4)d + (n-5)e = (n-2)^3$$
• Total cubes: $$a+b+c+d+e = n^2$$

This has solutions like $$a = 1, b = 6, c = e - (n-5)(2n-6), d = 3(n-1)(n-2) - e, e = e$$.

In particular, we don't need to use the "6 surface" cube.