Instant Insanity

The math behind it

Four cubes, four colors, and a stack that has to look "all different" on every side. It sounds easy. Here's why it isn't, and how a little graph theory solves it in a few minutes with pencil and paper.

1. One cube has 24 orientations

Pick which of the 6 faces points up. Then you can still spin the cube about the vertical axis into 4 quarter-turn positions. Every position of a cube is exactly one of those choices:

6 faces that could be on top × 4 quarter-turns = 24 orientations

Spinning, tilting and rolling never separate two opposite faces, so each cube always keeps the same three opposite pairs. That fact is the key to the whole puzzle.

2. Counting stacks

Cubes in a fixed order, each in any of 24 orientations244 = 331,776
…and the order of the cubes may also change (4! = 24 orders)4! × 244 = 7,962,624
"Essentially different" stacks: divide by the tower's 8 symmetries and the 24 orders7,962,624 ÷ (8 × 24) = 41,472

Why 8 symmetries? Turn the whole tower about its vertical axis (4 ways), and optionally flip it upside down (×2). You're looking at the same stack, so those shouldn't count as different. And the cube order doesn't matter for winning: each side just needs four different colors, wherever they sit. So 41,472 = 331,776 ÷ 8 = 3 × 243.

3. How many winners?

Up to symmetryexactly 1
With the cube order fixed8 of 331,776
If order counts too192 of 7,962,624

The chance a random stack wins is 1 in 41,472, about 0.0024%.

Imagine building a fresh random stack once per second. If you might repeat stacks, you'd expect about 41,472 tries, roughly 11.5 hours. If you're organized and never repeat a stack, on average you'd hit the winner halfway through the list: about 20,736 tries, or 5.75 hours. Either way, guessing is a bad plan.

How far is any stack from a win?

Count one quarter-turn of one cube as a move. A single cube can reach any of its 24 orientations in at most 3 moves (1 orientation needs 0 moves, 6 need 1, 11 need 2, 6 need 3). Checking all 331,776 stacks by computer: every stack can be solved in 8 moves or fewer, and the average is about 5.4. Only 2,688 stacks actually need all 8.

4. The graph theory solution

Make a graph with 4 vertices, one per color. For each cube, draw 3 edges, one for each pair of opposite faces, joining the two colors on that pair. Label the edge with the cube's number. If both faces of a pair are the same color you get a loop.

Graph with vertices R, G, W, B at the corners of a square. Twelve edges, three per cube, colored by cube number.

What we're looking for

Two edge-disjoint subgraphs, each one

The first tells you what goes on the front and back of each cube; the second, the left and right. Degree 2 means that color shows up exactly once on the front and once on the back. Edge-disjoint means no opposite pair is asked to face two ways at once.

Front/back: R –1– G –4– W –2– B –3– R
Left/right: R –4– G –3– W –1– B –2– R

To build the stack, walk around each cycle in one direction. An edge going R –1– G means "cube 1 has R in front and G behind." For left/right, the walk gives cube 4 R on the left and G on the right, and so on. Each cube's remaining pair goes on top and bottom. Done!

Fun check

Count each vertex's degree (a loop counts 2). You get R 7, G 6, B 5, W 6, exactly the number of faces of each color across all four cubes. That always works: every face is the end of exactly one edge.

5. A little history

6. The bigger picture

With n cubes and n colors, deciding whether a set of cubes has a solution is NP-complete (Robertson & Munro, 1978). That puts it with the famously hard problems that no one knows how to solve quickly in general. The graph trick works great for 4 cubes, but it doesn't scale to big ones.

Across all possible 4-cube puzzles, the most solutions any set can have is 72. The classic set is designed to have just one.

Try it yourself

1. A cube sits with red on top. How many ways can you turn it so red stays on top?

4: the four quarter-turns about the vertical axis. Do that for each of the 6 faces and you get 6 × 4 = 24.

2. Why does every color need degree exactly 2 in a solution subgraph?

The front/back subgraph has one edge per cube, so it describes 4 front faces and 4 back faces. Each color must appear once on the front and once on the back: 2 edge-ends per color.

3. Why can't a loop be in a solution subgraph here?

A loop already gives its color degree 2, so the other three cubes would have to form a triangle on the other three colors. Cube 1's R–R loop would need edges G–B, B–W and W–G, but no cube has a G–B pair. Cube 2's G–G loop would need R–B, B–W and R–W from cubes 1, 3 and 4. Cube 1 can only give B–W, and then cube 4 can only give B–W too. Both are dead ends.

4. Why must the two subgraphs be edge-disjoint?

Each edge is one opposite pair of one cube. That pair can face front/back or left/right, but not both at once.

5. Quick calculation: what is 245? Why does it equal 4! × 244?

245 = 7,962,624. It matches because 4! = 24, so 4! × 244 = 24 × 244.

← Back to the puzzle