Jaap's Puzzle Page

Rolling Cubes Puzzle

Rolling Cubes Puzzle

This puzzle consists of a square 3×3 tray with eight cubes in it. The cubes are identical, and each side of a cube is a different colour. There are ridges on the base of the tray so if you push a cube towards the vacant space it will easily roll over. By rolling the cubes around they get mixed up. The aim is to arrange them so that the space is in the middle and that the cubes show all the same colour on top. A more difficult challenge is to have the space in the middle and all the cubes in the exact same orientation, i.e. not only do the top faces match, the sides match as well.

The puzzle was invented by John Harris, and discussed in Martin Gardner's Mathematical Games column in the Scientific American, March and April 1975. In that original version only the top faces of the cubes are coloured, and the aim is to find the shortest sequence that leaves all the cubes turned upside down, with the gap in the middle. A more difficult version is mentioned too, in which all 24 outwardly visible faces are red, all 24 unexposed faces (i.e. touching faces and bottom sides) are not coloured. Here the aim is to go from being completely red on the outside to completely uncoloured. By the way, the inventor is not the same John Harris who invented the Astrolabacus puzzle.

If your browser supports JavaScript, then you can play the Eight Cubes Puzzle by clicking the link below:

JavaScript Eight Cubes Puzzle

The number of positions:

Suppose you only want to solve one colour on top. Each cube has 6 sides where this colour can be. The eight cubes therefore have 68=1,679,616 possible orientations. Their permutation does not matter, except for the position of the vacant space. There are thus 9·68 = 15,116,544 positions.
If you want to solve all the colours then it matters where they are, and so the cubes each have 24 possible orientations. The permutation of the cubes again does not matter as they are identical. The total number of positions is therefore at most 9·248=990,677,827,584. Not all these positions can be achieved however because there is an awkward parity constraint. A cube orientation has an even or odd parity according to whether an even or an odd number of quarter turns are needed to fix it. A cubes orientation parity will then depend on its position in the tray compared to its starting position. The cubes therefore split into two sets of four, those that started at a corner and those that started at an edge. There are 9!/4!2 = 630 ways to permute the two sets in the tray, giving a total of only 630·128=270,888,468,480 positions.

I have let my computer calculate God's Algorithm for the version of this puzzle where only the top faces of the eight cubes are coloured. The results are shown in the table below.

Depth   Positions
01
14
28
38
416
532
664
780
8148
9224
10448
11632
121,216
131,768
143,464
154,960
169,482
Depth   Positions
1713,296
1825,484
1935,744
2067,096
2190,584
22166,558
23217,612
24383,604
25466,092
26767,211
27838,724
281,260,208
291,208,772
301,631,240
311,342,312
321,618,467
331,145,324
Depth   Positions
341,237,172
35756,312
36734,955
37386,164
38333,095
39150,940
40118,538
4146,444
4232,322
4310,656
446,381
451,564
46858
47204
4844
4912
Total:15,116,544
Avg Depth30.710

The 12 antipodal positions are rotations/reflections of the following two patterns:

    

In the previous table rolling any cube one step is counted as one move. If instead we only consider positions with the space in the centre, and count the simple sequences of 4 moves that keep the space in the centre, then the result is as shown below.

Depth   Positions
01
18
244
3248
41,338
57,084
634,580
7143,588
8409,552
9601,887
10371,928
1196,678
1211,878
13796
146
Total:1,679,616
Avg Depth8.8611

The 6 antipodal positions are rotations/reflections of the following two patterns:

    

Solution:

Before you start the solution, move the cubes so that the space is in the centre. At the start and end of every step in the solution the space will be in the centre.

Notation:

I will call the four orthogonal directions left, right, back and front. There are several simple move sequences that move some cubes but leave the space in the centre afterwards. Suppose you roll the back cube forward, then roll a cube right, then one backwards, and finally the centre cube leftwards. This cycles the back, left and beck-left cubes around clockwise. This sequence will be denoted by BL. The inverse of this, i.e. rolling right, front, left, back, will be denoted by BL'.
Similarly the cubes at the back right can be cycled clockwise (left, front, right, back) which is denoted by BR, or anti-clockwise (front, left, back, right) denoted by BR'.
Cycling the front left cubes is denoted FL and FL', and finally the front right cubes FR and FR'.

Solving one colour only:
This solution places a single colour on top. The colours around the sides remain mixed.

  1. Choose which colour you want to end up on the top of the cubes.
  2. Do whatever moves you like to turn as many cubes as possible with the correct colour on top.
  3. If the back middle edge cube is incorrectly oriented, then see which side the chosen colour is on, and do the corresponding sequence:
    Back face: BL' BL'
    Right face: BL FL FL BL' BL' BL'
    Left face: BR' FR' FR' BR BR BR
    Bottom face: BR' FR' FL' FL' FR BR BR BR
    Front face: FR FR FR FR BR' FR FR FR BR
    The sequence will orient that cube correctly, but may leave it at a different position.
  4. If the back left corner cube is incorrectly oriented, then see which side the chosen colour is on, and do the corresponding sequence:
    back: FL FL BL BL BL BL
    left: BR' BR' BL' BL' BL' BL'
    front: BR BR BR BL' BL' BR'
    right: FL' FL' FL' BL BL FL
    bottom: FR FR FR BR BL' BL' BR' FR'
    The sequence will orient that cube correctly, but may leave it at a different position.
  5. If there is still some unsolved cube, then hold the tray so that that cube lies at the back or the back left, and go back to step c.

Solving all colours:
This solution orients the cubes exactly the same, so that the colours around the sides match too. If the cubes have been randomly placed in the tray the it is likely not possible, so only try this if the puzzle has been mixed from the starting position.

  1. Solve the top colour as explained above.
  2. Choose which colour should be on the front side of the cubes.
  3. Hold the tray so that as many cubes as possible have that colour on the front or back.
  4. If there are no cubes with the chosen colour on the left or right side, then jump to step h.
  5. Find a corner cube and an edge cube that need a quarter turn (i.e. have the chosen colour on the left or right side).
  6. Hold the tray such that the edge cube is at the back, and do the sequence below corresponding to the where the corner cube is:
    back left: BL' BL' BR BR BL BL BR' BR'
    back right: BR BR BL' BL' BR' BR' BL BL
    front left: FR' FR' FL' FL' BR' BR' FR' FR'
    front right: FL FL FR FR BL BL FL FL
  7. Repeat steps c-f until all the cubes have the chosen colour at the front or back.
  8. Hold the tray so that as many cubes as possible have the chosen colour on the front.
  9. If there is a corner cube which is the wrong way around, then hold the tray so that that corner is at the back left, and do:
    BL' BL' BR' BR' BR' BL BL BL BR BR BR BL'
  10. If there is an edge cube which is the wrong way around, then hold the tray so that that cube is at the back, and do:
    BR BL' BR BL' BR BL BR' BL BR' BL
  11. Repeat steps i-j until all corner cubes are correct.

Neat sequences:

  1. To keep the same top colour, and rotate every cube a quarter turn, do:
    BL BL BR BR BL FR FL' FL' FR FL FL FL FL BL'
  2. To keep the same top colour, and rotate everything a half turn, do:
    BL FR FL FR BR BL BL FR FR BR BL FL BL FR
  3. To turn the colour on the left to the top (and turn the current top colour to the back), do:
    BL BL FR FR BR' BL BL FL' FR FL' FL' BL' FR FL'