Algorithms For Solving Rubik's Cubes: June 2011
Algorithms For Solving Rubik's Cubes: June 2011
Algorithms For Solving Rubik's Cubes: June 2011
net/publication/51913939
CITATIONS READS
10 16,116
5 authors, including:
Anna Lubiw
University of Waterloo
181 PUBLICATIONS 2,441 CITATIONS
SEE PROFILE
All content following this page was uploaded by Anna Lubiw on 21 May 2014.
3
Department of Computer Science, Tufts University,
Medford, MA 02155, USA, awinslow@cs.tufts.edu
Abstract. The Rubik’s Cube is perhaps the world’s most famous and
iconic puzzle, well-known to have a rich underlying mathematical struc-
ture (group theory). In this paper, we show that the Rubik’s Cube also
has a rich underlying algorithmic structure. Specifically, we show that
the n × n × n Rubik’s Cube, as well as the n × n × 1 variant, has a “God’s
Number” (diameter of the configuration space) of Θ(n2 / log n). The up-
per bound comes from effectively parallelizing standard Θ(n2 ) solution
algorithms, while the lower bound follows from a counting argument.
The upper bound gives an asymptotically optimal algorithm for solving
a general Rubik’s Cube in the worst case. Given a specific starting state,
we show how to find the shortest solution in an n × O(1) × O(1) Rubik’s
Cube. Finally, we show that finding this optimal solution becomes NP-
hard in an n × n × 1 Rubik’s Cube when the positions and colors of some
of the cubies are ignored (not used in determining whether the cube is
solved).
1 Introduction
A little over thirty years ago, Hungarian architecture professor Ernő Rubik re-
leased his “Magic Cube” to the world.4 What we now all know as the Rubik’s
Cube quickly became a sensation [26]. It is the best-selling puzzle ever, at over
350 million units [15]. It is a tribute to elegant design, being part of the perma-
nent collection of the Museum of Modern Art in New York [18]. It is an icon for
difficult puzzles—an intellectual Mount Everest. It is the heart of World Cube
Association’s speed-cubing competitions, whose current record holders can solve
a cube in under 7 seconds (or 31 seconds blindfold) [1]. It is the basis for cube
art, a form of pop art made from many carefully unsolved Rubik’s Cubes. (For
4
Similar puzzles were invented around the same time in the United States [9][17], the
United Kingdom [6], and Japan [10] but did not reach the same level of success.
2 E. D. Demaine, M. L. Demaine, S. Eisenstat, A. Lubiw, A. Winslow
example, the recent movie Exit Through the Gift Shop features the street cube
artist known as Space Invader.) It is the bane of many computers, which spent
about 35 CPU years determining in 2010 that the best algorithm to solve the
worst configuration requires exactly 20 moves—referred to as God’s Number [22].
To a mathematician, or a student taking abstract algebra, the Rubik’s Cube
is a shining example of group theory. The configurations of the Rubik’s Cube,
or equivalently the transformations from one configuration to another, form a
subgroup of a permutation group, generated by the basic twist moves. This
perspective makes it easier to prove (and compute) that the configuration space
falls into two connected components, according to the parity of the permutation
on the cubies (the individual subcubes that make up the puzzle). See [7] for how
to compute the number of elements in the group generated by the basic Rubik’s
Cube moves (or any set of permutations) in polynomial time.
To a theoretical computer scientist, the Rubik’s Cube and its many gen-
eralizations suggest several natural open problems. What are good algorithms
for solving a given Rubik’s Cube puzzle? What is an optimal worst-case bound
on the number of moves? What is the complexity of optimizing the number of
moves required for a given starting configuration? Although God’s Number is
known to be 20 for the 3 × 3 × 3, the optimal solution of each configuration in
this constant-size puzzle still has not been computed [22]; even writing down
the first move in each solution would take about 8 exabytes (after factoring out
symmetries). While computing the exact behavior for larger cubes is out of the
question, how does the worst-case number of moves and complexity scale with
the side lengths of the cube? In parallel with our work, these questions were
recently posed by Andy Drucker and Jeff Erickson [4]. Scalability is important
given the commercially available 4 × 4 × 4 Rubik’s Revenge [25]; 5 × 5 × 5 Profes-
sor’s Cube [13]; the 6 × 6 × 6 and 7 × 7 × 7 V-CUBEs [28] whose design enables
cubes as large as 11×11×11 according to Verdes’s design patent [30]; Leslie Le’s
3D-printed 12 × 12 × 12 [14]; and Oskar van Deventer’s 17 × 17 × 17 Over the Top
and his 2 × 2 × 20 Overlap Cube, both available from 3D printer shapeways [29].
at once, to the extent that multiple cubies want the same move to be applied at
a particular time. We show that this parallelism can be exploited to reduce the
number of moves by a logarithmic factor, to O(n2 / log n). Furthermore, an easy
counting argument shows an average-case lower bound of Ω(n2 / log n), because
2
the number of configurations is 2Θ(n ) and there are O(n) possible moves from
each configuration.
Thus we settle the diameter of the n × n × n and n × n × 1 Rubik’s Cubes, up
to constant factors. These results are described in Sections 4 and 3, respectively.
Optimization algorithms. We give one positive and one negative result about
finding the shortest solution from a given configuration of a generalized Rubik’s
Cube puzzle. On the positive side, we show in Section 6 how to compute the ex-
act optimum for n × O(1) × O(1) Rubik’s Cubes. Essentially, we prove structural
results about how an optimal solution decomposes into moves in the long dimen-
sion and the two short dimensions, and use this structure to obtain a dynamic
program. This result may prove useful for optimally solving configurations of
Oskar van Deventer’s 2 × 2 × 20 Overlap Cube [29], but it does not apply to the
3 × 3 × 3 Rubik’s Cube because we need n to be distinct from the other two side
lengths. On the negative side, we prove in Section 5 that it is NP-hard to find
an optimal solution to a subset of cubies in an n × n × 1 Rubik’s Cube. Phrased
differently, optimally solving a given n × n × 1 Rubik’s Cube configuration is
NP-hard when the colors and positions of some cubies are ignored (i.e., they are
not considered in determining whether the cube is solved).
2 Common Definitions
in total. We say that a Rubik’s Cube is solved when each face of the cube is the
same color, unique for each face.
A slice of a Rubik’s Cube is a set of cubies that match in one coordinate
(e.g. all of the cubies such that y = 1). A legal move on a Rubik’s Cube involves
rotating one slice around its perpendicular5 . In order to preserve the shape
of the cube, there are restrictions on how much the slice can be rotated. If
the slice to be rotated is a square, then the slice can be rotated 90◦ in either
direction. Otherwise, the slice can only be rotated by 180◦ . Finally, note that if
one dimension of the cube has length 1, we disallow rotations of the only slice in
that dimension. For example, we cannot rotate the slice z = 0 in the n × n × 1
cube.
A configuration of a Rubik’s Cube is a mapping from each visible face of each
cubie to a color. A reachable configuration of a Rubik’s Cube is a configuration
which can be reached from a solved Rubik’s Cube via a sequence of legal moves.
For each of the Rubik’s Cube variants we consider, we will define the contents
of a cubie cluster. The cubies which belong in this cubie cluster depend on the
problem we are working on; however, they do share some key properties:
Each cubie cluster has a cluster configuration mapping from each visible face of
the cubie cluster to its color. Because the number of cubies in a cubie cluster is
constant, the number of possible cluster configurations is also constant.
We say that a move affects a cubie cluster if the move causes at least one
cubie in the cubie cluster to change places. Similarly, we say that a sequence of
moves affects a cubie cluster if at least one cubie in the cubie cluster will change
position or orientation after the sequence of moves has been performed.
Lemma 2. All six cluster configurations from Lemma 1 can be solved using a
sequence of at most six moves that does not affect the position of any cubies not
in the cubie cluster. (See Fig. 1.)
6 E. D. Demaine, M. L. Demaine, S. Eisenstat, A. Lubiw, A. Winslow
V1 V2 V1 V2 V1 V2
H1 H1 H1
H2 H2 H2
V1 V2 V1 V2 V1 V2
H1 H1 H1
H2 H2 H2
Fig. 1. The reachable cluster configurations and the move sequences to solve them.
Proof. The correct move sequence for each configuration from Lemma 1 is given
in Fig. 1. The fact that we always use each move twice ensures that all other
clusters will not be affected by the move sequence. The correctness of these
sequences can be verified by the reader. t
u
In order to handle the edge, corner, and cross clusters, we need a more
complicated sequence of moves. These clusters cannot always be solved without
affecting any other cubes. So rather than show that we can solve each cluster
individually, we show that we can solve all such clusters together.
Proof. We begin by solving the corner cluster, and, if n is odd, the center cluster
and the two edge cross clusters. These four clusters combined have only O(1)
reachable configurations, and so all four can be obviously be fixed in O(1) moves,
disregarding the effect that these moves might have on any other clusters. Next
we solve the other edge clusters. Our goal is to solve each cluster without affecting
any of the clusters we have previously solved.
Without loss of generality, say that we are trying to solve an edge cluster
with coordinates (x, 0). We begin by using the move sequences from Lemma 2
to make sure that the cluster has all four red stickers visible. Then it will be in
one of the states depicted in Fig. 2. To solve the cluster, we can use the move
sequences given in Fig. 2. Although the given move sequences are not guaranteed
to apply the identity permutation to all other clusters, they do have the property
that any horizontal move will be performed an even number of times. Hence, this
Algorithms for Solving Rubik’s Cubes 7
move sequence will apply the identity permutation to all other edge clusters. In
addition, none of the move sequences affect the center cubie.
V1 V2 V1 V2 V1 V2 V1 V2
H1 H1 H1 H1
H2 H2 H2 H2
Fig. 2. When all four red stickers are facing forwards, these are the possible configu-
rations for an edge cluster, and the move sequences used to solve them.
Once all the edge clusters have been solved, we want to solve the cross clus-
ters. We know that the center cluster has already been solved. We also know that
there are O(n) cross clusters, so if we can solve each cross cluster in O(1) moves
without affecting the rest of the clusters, then we will have solved the edge and
cross clusters in a total of O(n) moves. Without loss of generality, say that we
are trying to solve the cross cluster ((n − 1)/2, y). The four possible states for a
cross cluster are depicted in Fig. 3.
V V V V
H1 H1 H1 H1
H2 H2 H2 H2
Fig. 3. The four reachable configurations for a cross cluster. Two of them can be
solved without affecting the rest of the clusters.
However, because we have already solved all of the edge clusters, we know
that the set of possible configurations for our cross cluster is more restricted.
Both horizontal moves affecting our cross cluster will cause one of the two cubies
to change color. No matter what state the cross cluster is in, the vertical move
cannot change the color of only one cubie. Therefore, if the cross cluster is in
the configuration depicted in Fig. 3(b) or the configuration depicted in Fig. 3(c),
then the rest of the solution must perform either the move H1 or the move H2
an odd number of times.
Consider the effect of this on the edge cluster affected by H1 and H2 . Each
move in the edge cluster causes a swap of two cubies. If an order is placed on
8 E. D. Demaine, M. L. Demaine, S. Eisenstat, A. Lubiw, A. Winslow
the cubies in the cluster, each swap is a permutation of this order, and the
set of permutations constructible using swaps is equivalent to the permutation
group on 4 elements, S4 . By permutation group theory, if a particular cluster
configuration can be solved using an even number of swaps, then any solution
for that cluster configuration has an even number of swaps. We know that the
edge cluster is already solved, so it can be solved using an even number of swaps.
So if the rest of the solution contains an odd number of moves H1 and H2 , then
it must also contain an odd number of edge moves V1 and V2 .
H
(a) (b) (c) (d)
V2 V2 V1 V1
V1 V1 V2 V2
Now consider the effect of an odd number of edge moves on the affected
edge cross cluster. Figure 4 gives the configuration space for that cluster. We
know that it is currently in the solved state labelled (a). Any sequence of moves
which contains an odd number of edge moves V1 and V2 will cause the edge cross
cluster to leave the solved state. So the rest of the solution cannot contain an
odd number of edge moves V1 and V2 . This means that the rest of the solution
cannot contain an odd number of horizontal moves H1 and H2 affecting a single
cross cluster. So every cross cluster must be in one of the states depicted in
Figs. 3(a) and 3(d), each of which can be solved without affecting any other
clusters using the sequence of moves listed for each state. t
u
There are n2 clusters in the n×n×1 Rubik’s Cube. If we use the move sequences
given in Fig. 1 to solve each cluster individually, we have a sequence of O(n2 )
moves for solving the entire cube. In this section, we take this sequence of moves
and take advantage of parallelism to get a solution with O(n2 / log n) moves.
Say that we are given columns X and rows Y such that all of the cubie clusters
(x, y) ∈ X × Y are in the configuration depicted in Fig. 1(b). If we attempted
Algorithms for Solving Rubik’s Cubes 9
to solve each of these clusters individually, the number of moves required would
be O(|X| · |Y |).
Consider instead what would happen if we first flipped all of the columns
x ∈ X, then flipped all of the rows y ∈ Y , then flipped all of the columns x ∈ X
again, and finally flipped all of the rows y ∈ Y again. What would be the effect
of this move sequence on a particular (x∗ , y ∗ ) ∈ X ×Y ? The only moves affecting
that cluster are the column moves x∗ and (n − 1 − x∗ ) and the row moves y ∗
and (n − 1 − y ∗ ). So the subsequence of moves affecting (x∗ , y ∗ ) would consist of
the column move x∗ , followed by the row move y ∗ , followed by the column move
x∗ again, and finally the row move y ∗ again. Those four moves are exactly the
moves needed to solve that cluster.
This idea allows us to parallelize the solutions for multiple clusters, resulting
in the following lemma.
We claim that this new sequence of moves will solve all cubie clusters (x, y) ∈
X × Y , and that no other cubie clusters will be affected. To see that this is true,
consider how some cubie cluster (x∗ , y ∗ ) ∈ {0, 1, . . . , bn/2c−1}×{0, 1, . . . , bn/2c−
1} will be affected by the move sequence. If x∗ ∈ / X and y ∗ ∈ / Y , then none of the
moves in the sequence will affect the position of any cubies in the cubie cluster,
and therefore the cubie cluster will be unaffected. If x∗ ∈ X and y ∗ ∈ Y , then
10 E. D. Demaine, M. L. Demaine, S. Eisenstat, A. Lubiw, A. Winslow
the subsequence of moves which affect this cubie cluster will be exactly the se-
quence of moves necessary to solve this cubie cluster. Otherwise, either x∗ ∈ X
or y ∗ ∈ Y , but not both. Therefore, the subsequence of moves which affect this
cubie cluster will be either all vertical, or all horizontal, and each move will occur
exactly twice. This means that the subsequence of moves which affect this cubie
cluster will apply the identity permutation to this cubie cluster. t
u
This technique allows us to solve all cubie clusters (x, y) ∈ X × Y using only
O(|X| + |Y |) moves, if each one of those clusters is in the same configuration.
Our goal is to use this technique for a related problem: solving all of the cubie
clusters (x, y) ∈ X × Y that are in a particular cluster configuration c, leaving
the rest of the clusters alone. To that end, we divide up the columns X according
to the pattern of rows that are in configuration c, and solve each subset of the
rows using the technique of Lemma 4. More formally:
Lemma 5. Suppose we are given an n × n × 1 Rubik’s Cube configuration, a
cluster configuration c, and sets X, Y ⊆ {0, 1, . . . , bn/2c − 1} such that |X| = `.
Then all cubie clusters (x, y) ∈ X × Y that are in configuration c can be solved
in O(`2` + |Y |) moves without affecting the rest of the cubies.
Proof. For each y ∈ Y , we define Sy = {x ∈ X | the cubie cluster (x, y) is in
configuration c}. For each S ⊆ X, we let YS = {y ∈ Y | Sy = S}. There are
2` possible values for S. For each YS , we use the sequence of moves which is
guaranteed to exist by Lemma 4 to solve all (x, y) ∈ S × YS . This sequence of
moves has length O(|S| + |YS |) = O(` + |YS |). When we sum the lengths up for
all YS , we find that the number of moves is bounded by
!
X
`
|YS | = O ` · 2` + |Y | .
O `·2 +
S
t
u
Unfortunately, this result is not cost-effective. We need to make sure that
` is small enough to prevent an exponential blowup in the cost of solving the
Rubik’s Cube. To that end, we divide up the columns into small groups to get
the following result:
Lemma 6. Suppose we are given an n × n × 1 Rubik’s Cube configuration, a
cluster configuration c, and sets X, Y ⊆ {0, 1, . . . , bn/2c − 1}. Then all cubie
clusters (x, y) ∈ X × Y that are in configuration c can be solved in O(|X| ·
|Y |/ log |Y |) moves without affecting the rest of the cubies.
p
Proof. Let ` = 21 log2 |Y |, so that 2` = |Y |. Let k = d|X|/`e. Partition the set
X into a series of sets X1 , . . . , Xk each of which has size ≤ `. For each Xi , we
solve the cubie clusters in Xi × Y using the sequence of moves that is guaranteed
to exist by Lemma 5. The number of moves required to solve a single Xi is
`
1 p
O `2 + |Y | = O log2 |Y | |Y | + |Y | = O(|Y |).
2
Algorithms for Solving Rubik’s Cubes 11
Therefore, if we wish to perform this for k sets, the total number of moves
becomes:
|X| |X| · |Y |
O (k · |Y |) = O 1 · |Y | = O
2 log2 |Y |
log |Y |
t
u
Proof. In order to solve the Rubik’s Cube, we must solve all cubie clusters
(x, y) ∈ {0, 1, . . . , bn/2c−1}×{0, 1, . . . , bn/2c−1}. To do so, we loop through the
six possible cluster configurations, then use the sequence of moves guaranteed to
exist by Lemma 6 to solve all of the cubie clusters which are in a particular con-
figuration. For a single configuration, the number of moves that this generates
is
2
bn/2c · bn/2c n
O =O .
log(bn/2c) log n
When we add this cost up for the six different configurations, the total number
of moves is 6 · O(n2 / log n) = O(n2 / log n). t
u
Proof. Lemma 2 shows that for every possible configuration of a cubie cluster,
there exists a sequence of moves to solve the cubie cluster while leaving the rest
of the cubies in the same location. Hence, the inverse of such a sequence will
transform a solved cubie cluster to an arbitrary cluster configuration without af-
fecting any other cubies. Not counting the edge cubies and the cross cubies, there
2
are (bn/2c − 1) cubie clusters, each of which can be independently placed into
2
one of six different configurations. This means that there are at least 6(bn/2c−1)
reachable configurations.
There are 2n possible moves. Therefore, the total number of states reachable
using at most k moves is at most
(2n)k+1 − 1
≤ (2n)k+1 .
2n − 1
12 E. D. Demaine, M. L. Demaine, S. Eisenstat, A. Lubiw, A. Winslow
Therefore, if k is the number of moves necessary to reach all states, it must have
the property that:
2
6(bn/2c−1) ≤ (2n)k+1 ,
2 (k + 1) log 2n
(bn/2c − 1) ≤ log6 (2n)k+1 = ,
log 6
2
(bn/2c − 1) log 6
− 1 ≤ k.
log 2n
Hence, there must exist some configurations which are Ω(n2 / log n) moves away
from solved. t
u
Just as it was for the n × n × 1 cube, our goal is to prove that for each cluster
configuration, there is a sequence of O(1) moves which can be used to solve the
cluster, while not affecting any other clusters. For the n × n × 1 cube, we wrote
these solution sequences using the symbols H1 , H2 , V1 , V2 to represent a general
class of moves, each of which could be mapped to a specific move once the cubie
cluster coordinates were known. Here we introduce more formal notation.
Because of the coordinate system we are using, we distinguish two types of
legal moves. Face moves involve taking a single face and rotating it 90◦ in either
direction. Row or column moves involve taking a slice of the cube (not one of its
faces) and rotating the cubies in that slice by 90◦ in either direction. Face moves
come in twelve types, two for each face. For our purposes, we will add a thirteenth
type which applies the identity function. If a is the type of face move, we write
Fa to denote the move itself. Given a particular index i ∈ {1, 2, . . . , bn/2c − 1},
there are twelve types of row and column moves that can be performed — three
different axes for the slice, two different indices (i and n − i − 1) to pick from,
and two directions of rotation. Again, we add a thirteenth type which applies
the identity function. If a is the type of row or column move, and i is the index,
then we write RCa,i to denote the move itself.
A cluster move sequence consists of three type sequences: face types a1 , . . . , a` ,
row and column types b1 , . . . , b` , and row and column types c1 , . . . , c` . For a cu-
bie cluster (x, y), the sequence of actual moves produced by the cluster move
sequence is Fa1 , RCb1 ,x , RCc1 ,y , . . . , Fa` , RCb` ,x , RCc` ,y . A cluster move solution
for a cluster configuration d is a cluster move sequence with the following prop-
erties:
1. For any (x, y) ∈ {1, 2, . . . , bn/2c − 1} × {1, 2, . . . , bn/2c − 1}, if cluster (x, y)
is in configuration d, then it can be solved using the sequence of moves
Fa1 , RCb1 ,x , RCc1 ,y , . . . , Fa` , RCb` ,x , RCc` ,y .
2. The move sequence Fa1 , RCb1 ,x , RCc1 ,y , . . . , Fa` , RCb` ,x , RCc` ,y does not af-
fect cubie cluster (y, x).
3. All three of the following sequences of moves do not affect the configuration
of any cubie clusters:
Our goal is to construct a cluster move solution for each possible cubie cluster
configuration, and then use the cluster move solution to solve multiple cubie
clusters in parallel.
In the speed cubing community, there is a well-known technique for solving
n × n × n Rubik’s Cubes in O(n2 ) moves, involving a family of constant-length
cluster move sequences. These cluster move sequences can be combined to con-
struct constant-length cluster move solutions for all possible cluster configura-
tions, which is precisely what we wanted.
14 E. D. Demaine, M. L. Demaine, S. Eisenstat, A. Lubiw, A. Winslow
Before dealing with the general solution, we address fixing the parity of the
cubie clusters. This allows us to assume that the parity of all clusters is even for
the remainder of the paper.
2
3
4
5 6 7 8
12 11 10 9
13 14 15 16
20 19 18 17
21
22
23
24
Proof. By definition, the center cluster is already solved, and therefore we may
assume that its parity is already even. In addition, any cluster containing at
least two indistinguishable cubies can be considered to have even parity or odd
parity depending on the chosen label for the indistinguishable cubies. Therefore,
we may assume that all such clusters have even parity. This means that all non-
edge clusters, including the non-edge cross clusters, can be assumed to have the
correct parity no matter how many moves are performed. So we need only fix
the parity of the edge clusters.
We begin by fixing the parity of the corner cluster and the edge cross cluster
(if it exists). Because the cube is solvable, we know that the corner cluster and the
edge cross cluster can be solved. Because the corner cluster has O(1) reachable
states and the edge cross cluster has O(1) reachable states, we know that we can
solve both in O(1) moves. Once those two clusters are solved, we know that their
parities must be correct. Therefore, there is a sequence of O(1) moves which can
be used to fix the parity of those clusters.
Consider the effect of a face move on the parity of a non-cross edge cluster.
For a particular edge cluster, a face move affects the location of eight cubies,
due to the fact that a face move also acts like a row or column move for edge
cubie groups. The color of each cubie is rotated 90◦ in the direction of the face’s
rotation. This means that the permutation applied consists of two permutation
cycles each containing four elements. Therefore, if the elements whose colors
Algorithms for Solving Rubik’s Cubes 15
Lemma 8. For each permutation in Table 1, there exists a cluster move se-
quence of length O(1) which can be used to apply the given permutation to the
cluster while applying the identity permutation to every other cluster.
Proof. First, we introduce some more notation for Rubik’s Cube moves. It is
more specific than the formalism of the cluster move sequence introduced above,
making it easier to express a particular set of moves, but is more difficult to
analyze when we parallelize this move sequence.
Consider facing the cube from in front (the front face is the face in the
xz-plane with the more negative y-value). From this view, there are horizontal
moves that rotate a slice of the cube parallel to the xy-plane. Rotating the ith
slice from the top in the clockwise direction 90◦ as viewed from above the cube is
denoted by HiCW . Rotating this same slice in the opposite direction is denoted by
HiCCW . Similarly, rotating a slice parallel to the yz-plane is a vertical move, and
rotating the jth slice from the left side of the cube in the clockwise direction
as viewed from left of the cube is denoted VjCW , while the counter-clockwise
version is denote VjCCW . Finally, we define a third type of move which rotates a
slice parallel to the front face. Counting inward from the front face, we denote
rotating the kth slab 90◦ clockwise as DkCW , while rotating it 90◦ in the opposite
direction is DkCCW . See Figure 7.
We claim that the move sequence S = VnCCW ◦ Dm CW
◦ VnCW ◦ Dm CCW
◦ H0CW ◦
CW CCW CCW CW CCW
Dm ◦Vn ◦Dm ◦Vn ◦H0 swaps the colors of three cubies in a single
cluster, while leaving the color configurations of all other clusters the same. This
move sequence is attributed to Ingo Schütze [24], but is fairly well-known within
the speed cubing community, so its origins are unclear. The effect of applying S
is shown by case analysis of individual cubies. When applying the sequence S,
only cubies lying on the union of the slices rotated by the Vn , Dn , and H0 moves
are affected.
Blocks lying on the bottom face are unaffected, as they never reach the top
face and thus only have the subsequence VnCCW ◦ Dm CW
◦ VnCW ◦ Dm CCW CW
◦ Dm ◦
CCW CCW CW
Vn ◦ Dm ◦ Vn applied, which does not affect the final location of a
16 E. D. Demaine, M. L. Demaine, S. Eisenstat, A. Lubiw, A. Winslow
DkCW
VjCCW
DkCCW
k i
VjCW
j
z
HiCW HiCCW y
x
cube. Blocks starting on the back and right faces never move to the upper face,
as each move that could place these on the upper face (moves VnCW and Dm CCW
)
is preceded by a move rotating these cubies onto the bottom face (moves VnCCW
CW
and Dm ).
CW CCW
Now consider the cubies on left face in the slice rotated by Dm and Dm .
Exactly one of these cubies is in the same cluster as the cubie on the upper face
that lies in the slices rotated by both VnCW and Dm CW
. All other such cubies
CW CCW
cannot be affected by Dm and Dm moves, so applying S has the same
CW CCW
effect as applying the sequence Dm ◦ Dm ◦ H0CW ◦ Dm CW
◦ DmCCW
◦ H0CCW .
CW CCW CW CCW
Canceling the Dm and Dm moves yields H0 , H0 and thus these cubies
are unaffected. Now consider the single cubie on the left face in the same cluster
as the cubie on the upper face that lies in the slices rotated by both VnCW and
CW
Dm . Tracing the locations visited by this cubie when S is applied to it shows
CW
that the cubie travels to the upper face (via Dm ), the front face (via LCWn ),
CCW CCW
the upper face (via Vn ), and then the left face (via Dm ). So the cubie’s
location is unaffected by S.
Next consider the cubies on the front face. Exactly one of these cubies is in
the same cluster as the cubie on the upper face that lies in the slices rotated
by both VnCW and Dm CW
. All other such cubies cannot be affected by VnCW
CCW
and Vn moves, so applying S has the same effect as applying the sequence
CW CCW
Dm ◦ Dm ◦ H0CW ◦ Dm CW
◦ DmCCW
◦ H0CCW . For the cubie in the same cluster
as the cubie on the upper face that lies on both the VnCW and Dm CW
slices,
applying S to it results in moving it, in sequence, to the left side of the upper
face (VnCCW ), right face (Dm CW CCW
), upper face (Dm ), the back side of the upper
face (H0 ), and the left side of the upper face (H0CCW ). So applying S to this
CW
cubie moves it to the location of the cubie in its cluster in the left side of the
upper face.
Finally, consider the cubies on the upper face. Divide the cubies into three
sets based upon the cubies in their clusters. Each cubie on the upper face either
Algorithms for Solving Rubik’s Cubes 17
is in the cluster containing the cubie lying in slices rotated by both VnCW and
CW
Dm , or is in a cluster containing a cubie lying in exactly one of the slices
rotated by VnCW and Dm CW
, or is in a cluster that does not contain any elements
in either of the slices rotated by VnCW and Dm CW
. If a cubie lies in a cluster that
does not contain any elements in either of the slices rotated by VnCW and Dm CW
,
CW CCW CW CCW
then it cannot be affected by Vn , Vn , Dm , or Dm moves. So applying
S to it is equivalent to applying H0CW , H0CCW to it, and thus does not affect
its position. If a cubie lies in the VnCW slice but is not in the cluster containing
the cubie in both VnCW and Dm CW
slices, then applying S to it is equivalent to
CCW
applying Vn CW CW
◦ Vn ◦ H0 ◦ VnCCW ◦ VnCW ◦ H0CCW (the identity) as it can
CW CW
never lie in the Dm slice. Similarly, if a cubie lies in the Dm slice but is not
CW CW
in the cluster containing the cubie in both Vn and Dm slices, then it can
never lie in the VnCW slice, and so applying S to it is equivalent to applying
CW CCW
Dm ◦ Dm ◦ H0CW ◦ Dm CW
◦ Dm CCW
◦ H0CCW , the identity.
Now consider the four cubies on the upper face in the same cluster as the
cubie lying in both VnCW and Dm CW
slices. The cubie lying on the left side of the
upper face is the cubie lying in both the VnCW and Dm CW
slices, and applying
S to it results in moving it, in sequence, to the upper side of the back face
(VnCCW ), the left side of the upper face (VnCW ), the bottom side of the left face
CCW CW
(Dm ), the left side of the upper face (Dm ), the upper side of the back face
CCW CW
(Vn ), the left side of the upper face (Vn ), and the front side of the upper
face (H0CCW ). So the result is moving the cubie from the left side to the front
side of the upper face. The cubie lying on the front side of the upper face initially
lies in neither the VnCW nor the Dm CW
slice. So the moves in S before H0CW do
no affect it. Applying the subsequence of moves starting at H0CW move it, in
sequence, to the left side of the upper face (H0CW ), the upper side of the right
CW CCW
face (Dm ), the left side of the upper face (Dm ), and the left side of the
CW
front face (Vn ). So the result is moving the cubie from the front side of the
upper face to the left side of the front face. The cubie lying on the back side
of the upper face moves visits the back face (VnCCW , VnCW ) and the right side
of the upper face (H0CW , H0CCW ), but is not affected by S, and the cubie lying
on the right side of the upper face only visits the front side of the upper face
(H0CW , H0CCW ) and thus is not affected by S.
11 11 11
19 19 19
22 22 22
Fig. 8. The resulting movement of the three cubies of a cluster resulting from applying
the move sequence S = VnCCW ◦ Dm CW
◦ VnCW ◦ Dm
CCW
◦ H0CW ◦ DmCW
◦ VnCCW ◦ DmCCW
◦
CW CCW
Vn ◦ H0 .
Lemma 9. Any cluster configuration with even parity can be solved using a
cluster move solution of length O(1).
Proof. By Lemma 8, there exist a set of permutations that can be applied to any
single cluster while applying the identity permutation to every other cluster. It
can be shown using the GAP software package [27] that this set of permutations
generates A24 , the set of even permutations on 24 elements. Thus any even
permutation can be written as a composition of these permutations and has
an inverse that can also be written as the composition of these permutations.
Because each cluster has finite size, the inverse composition must have O(1)
length. So there exists a O(1)-length sequence of moves that can be applied to
Algorithms for Solving Rubik’s Cubes 19
the cube that results in one cluster having the solved color configuration, and
all other cubie clusters having unchanged color configurations. t
u
Bulki = Fai , RCbi ,x1 , RCbi ,x2 , . . . , RCbi ,x` , RCci ,y1 , RCci ,y2 , . . . , RCci ,yk .
Note that this sequence consists of |X| + |Y | + 1 moves. We then construct the
full sequence of moves to be the following:
Because the original sequence of moves had length O(1), we know that ` = O(1),
and so the total length of this sequence will be O(|X| + |Y | + 1).
Consider the effect of this constructed move sequence on a cubie cluster
(x, y) ∈ {0, 1, . . . , bn/2c − 1} × {0, 1, . . . , bn/2c − 1}. First, consider the effect on
(x, y) ∈ X × Y . The subsequence of moves which affect this cubie cluster will
be Fa1 , RCb1 ,x , RCc1 ,y , . . . , Fa` , RCb` ,x , RCc` ,y . This is precisely the set of moves
generated by the cluster move solution for solving the cluster (x, y) so this cluster
will be solved. The subsequence of moves affecting the cluster (y, x) ∈ Y ×X. will
be the same as the subsequence for the cluster (x, y). By Property 2 of cluster
move solutions, this cluster will not be affected by the sequence of moves.
We need not consider the effect on clusters X×X or Y ×Y , because our lemma
places no restrictions on what happens to those clusters. So all of the remaining
clusters we must consider have at most one coordinate in X ∪ Y . Suppose we
have some x ∈ X and some z ∈ / X ∪ Y . Then the sequence of moves affecting
the clusters (x, z) and (z, x) will be Fa1 , RCb1 ,x , Fa2 , RCb2 ,x . . . , Fa` , RCb` ,x . By
Property 3 of cluster move solutions, this sequence of moves does not affect
20 E. D. Demaine, M. L. Demaine, S. Eisenstat, A. Lubiw, A. Winslow
any clusters, and so (x, z) and (z, x) will both remain unaffected. Similarly,
suppose we have some y ∈ Y and some z ∈ / X ∪ Y . Then the sequence of moves
affecting the clusters (y, z) and (z, y) is Fa1 , RCc1 ,y , Fa2 , RCc2 ,y . . . , Fa` , RCc` ,y .
According to Property 3, this move sequence does not affect the configuration
of clusters (y, z) or (z, y). Finally, consider the effect on some cluster (w, z) ∈
X ∪ Y × X ∪ Y . Then the sequence of moves affecting (w, z) is Fa1 , Fa2 , . . . , Fa` .
Once again, by Property 3 of cluster move solutions, this move sequence will not
affect the configuration of cluster (w, z). t
u
Now say that we are given a cluster configuration d and a set of columns X
and rows Y such that X ∩ Y = ∅. Using the same row-grouping technique that
we used for the n × n × 1 case, we show the following lemma.
t
u
solve the cubie clusters in Xi × Y using the sequence of moves that is guaranteed
to exist by Lemma 11. The number of moves required to solve a single Xi is
1 p
O `2` + |Y | = O
log2 |Y | |Y | + |Y | = O(|Y |).
2
Therefore, if we wish to perform this for k sets, the total number of moves
becomes
|X| |X| · |Y |
O (k · |Y |) = O 1 · |Y | = O .
2 log2 |Y |
log |Y |
t
u
To finish constructing the move sequence for the entire Rubik’s Cube, we
need to account for two differences between this case and the n × n × 1 case: the
requirement that X ∩ Y = ∅ and the potential to affect clusters in (X × X) ∪
(Y × Y ).
Theorem 3. Given an n × n × n Rubik’s Cube configuration, all cubie clusters
can be solved in O(n2 / log n) moves.
Proof. In order to solve the Rubik’s Cube, we must first fix the parity. Using the
techniques of Lemma 7, we can perform this step in O(n) moves. Then we solve
each edge cluster individually. Each edge cluster requires O(1) moves to solve,
and there are O(n) edge clusters, so this preliminary step takes time O(n).
Once p the edges have been solved, we want to solve the non-edge clusters.
Let k = n/2. Partition {0, 1, . . . , bn/2c − 1} into a series of sets G1 , . . . , Gk
each of which has size ≤ k. For each pair i, j such that i 6= j and each cluster
configuration c, we use the sequence of moves guaranteed to exist by Lemma 12
to solve all (x, y) ∈ Gi × Gj with the configuration c. This ensures that all cubie
clusters (x, y) ∈ Gi × Gj will be solved. For each i, we must also solve all cubie
clusters (x, y) ∈ Gi × Gi . There are k 2 (k − 1)/2 such cubie clusters, so we can
afford to solve each such cubie cluster individually.
What is the total number of moves required? For a single pair i 6= j and
a single configuration c, the number of moves required will be O(k 2 / log k) =
O(n/ log n). There are a constant number of possible configurations, so solving
a single pair i, j for all configurations will also require O(n/ log n) moves. There
are k 2 −k such pairs, for a total of O(n2 / log n). If we then add in the extra O(k 3 )
from the diagonals, then the total number of moves will be O(n2 / log n+n3/2 ) =
O(n2 / log n). t
u
Proof. Lemma 9 shows that for every possible configuration of a cubie cluster,
there exists a sequence of moves to solve the cubie cluster while leaving the rest
of the cubies in the same location. Hence, the inverse of such a sequence will
transform a solved cubie cluster to an arbitrary configuration without affecting
2
any other cubies. Not counting the edges, there are (bn/2c − 1) cubie clusters,
each of which can be independently placed into one of (24!)/(4!)6 different color
configurations. This means that there are at least
(bn/2c−1)2
24!
(4!)6
reachable configurations.
There are 6n possible moves, so the total number of states reachable using
at most k moves is at most
(6n)k+1 − 1
≤ (6n)k+1 .
6n − 1
Therefore, if k is the number of moves necessary to reach all states, it must have
the property that
(bn/2c−1)2
24!
≤ (6n)k+1 ,
(4!)6
2 24!
≤ log (6n)k+1 = (k + 1) log(6n),
(bn/2c − 1) · log 6
(4!)
2 24!
(bn/2c − 1) log (4!) 6
− 1 ≤ k.
log(6n)
Hence, there must exist some configurations which are Ω(n2 / log n) moves away
from solved. t
u
cubie cluster are either all important or all unimportant, and thus it does not
matter whether we aim to solve cubies (which move) or specific cubie positions
(which do not move). Therefore the problem remains NP-hard if we aim to solve
the puzzle in the sense of unifying the side colors, when we ignore the colors of
all unimportant cubies.
Certain properties of the Rubik’s Cube configuration can affect the set of
potential solutions. For the rest of this section, we will consider only Rubik’s
Cubes where n is odd and where all edge cubies and cross cubies are both
solved and marked important. This restriction ensures that for any cluster, the
number of horizontal moves and vertical moves affecting it must both be even.
In addition, we will only consider Rubik’s Cubes in which all cubie clusters
are in the cluster configurations depicted in Figures 1(a), 1(b), and 1(d). This
restriction means that the puzzle can always be solved using moves only of types
H1 and V1 . This combination of restrictions ensures that each unsolved cluster
must be affected by both vertical and horizontal moves.
Suppose that we are given a configuration and a list of important cubies. Let
ur be the number of rows of index ≤ bn/2c that contain at least one important
unsolved cubie. Let uc be the number of columns of index ≤ bn/2c that contain
at least one important unsolved cubie. Then we say that the ideal number of
moves for solving the given configuration is 2(ur + uc ). In other words, the ideal
number of moves is equal to the smallest possible number of moves that could
solve all the important cubies. An ideal solution for a subset of the cubies in a
particular n × n × 1 puzzle is a solution for that set of cubies which uses the ideal
number of moves. For the types of configurations that we are considering, the
ideal solution will contain exactly two of each move, and the only moves that
occur will be moves of type H1 or V1 .
Definition 1. Let Ik (m) denote the index in the solution of the kth occurrence
of move m.
For our hardness reduction, we develop two main gadgets. The first gad-
get forces an ordering on the second occurrences of row moves, and is used in
the construction of the second gadget. The second gadget forces a betweenness
constraint on the ordering of the first occurrences of row moves.
Lemma 13. Given two sets of columns X1 , X2 ⊆ {0, 1, . . . , bn/2c − 1}, there
is a gadget using three extra rows and two extra columns ensuring that, for all
x1 ∈ X1 and for all x2 ∈ X2 , I2 (x1 ) < I2 (x2 ). As a side effect, this gadget also
forces
max I1 (x1 ) < min I2 (x1 ) and max I1 (x2 ) < min I2 (x2 ).
x1 ∈X1 x1 ∈X1 x2 ∈X2 x2 ∈X1
Proof. Let ỹ1 , ỹ2 , ỹ3 ≤ bn/2c be three rows not used elsewhere in the construc-
tion. Let x̃1 , x̃2 ≤ bn/2c be two columns not used elsewhere in the construc-
tion. Make cubie clusters (x̃1 , ỹ2 ) and (x̃2 , ỹ3 ) have the configuration depicted
in Fig. 1(b); make cubie clusters (x̃1 , ỹ1 ) and (x̃2 , ỹ2 ) have the configuration
24 E. D. Demaine, M. L. Demaine, S. Eisenstat, A. Lubiw, A. Winslow
depicted in Fig. 1(d); and make cubie cluster (x̃2 , ỹ1 ) remain in the solved con-
figuration. Mark all of these cubie clusters as important.
These cluster configurations enforce the following constraints:
I1 (x̃1 ) < I1 (ỹ2 ) < I2 (x̃1 ) < I2 (ỹ2 ), I1 (x̃2 ) < I1 (ỹ3 ) < I2 (x̃2 ) < I2 (ỹ3 ),
I1 (ỹ1 ) < I1 (x̃1 ) < I2 (ỹ1 ) < I2 (x̃1 ), I1 (ỹ2 ) < I1 (x̃2 ) < I2 (ỹ2 ) < I2 (x̃2 ).
I1 (ỹ1 ) < I1 (x̃1 ) < I1 (ỹ2 ) < I1 (x̃2 ) and I2 (ỹ1 ) < I2 (x̃1 ) < I2 (ỹ2 ) < I2 (x̃2 ).
Because (x̃2 , ỹ1 ) must remain solved, and because of the above constraints, there
is only one possible ordering for the pairs of moves involving ỹ1 and x̃2 : I1 (ỹ1 ) <
I2 (ỹ1 ) < I1 (x̃2 ) < I2 (x̃2 ). If we combine this with the constraint I1 (x̃2 ) <
I1 (ỹ3 ) < I2 (x̃2 ) < I2 (ỹ3 ), we know that I1 (ỹ1 ) < I2 (ỹ1 ) < I1 (ỹ3 ) < I2 (ỹ3 ).
Now, for each x1 ∈ X1 and x2 ∈ X2 , make cubie clusters (x1 , ỹ1 ) and (x2 , ỹ3 )
have the configuration depicted in Fig. 1(b), and mark them important. No
other cubie clusters involving ỹ1 , ỹ2 , ỹ3 or x̃1 , x̃2 should be marked important.
This constraint ensures that for all x1 ∈ X1 , I2 (x1 ) must lie between I1 (ỹ1 ) and
I2 (ỹ1 ). In addition, for all choices of x2 ∈ X2 , I2 (x2 ) must lie between I1 (ỹ3 )
and I2 (ỹ3 ). Therefore, I2 (x1 ) < I2 (x2 ).
As a side effect, these constraints ensure that for all x1 ∈ X1 , I1 (x1 ) must
lie before I1 (ỹ1 ), while I2 (x1 ) lies after I1 (ỹ1 ). Therefore,
In addition, the constraints ensure that for all choices of x2 ∈ X2 , I1 (x2 ) must
lie before I1 (ỹ3 ), while I2 (x2 ) lies after I1 (ỹ3 ). This ensures that
We have shown that these gadgets can enforce a constraint. We must also
show that these gadgets do not enforce any constraints other than the ones
expressed in the lemma. In other words, given any solution which satisfies the
requirements given in the lemma, we must be able to insert the moves for our
new rows and columns in such a way that all important clusters will be solved. In
order to make sure that clusters (x̃1 , ỹ2 ), (x̃2 , ỹ3 ), (x̃1 , ỹ1 ), (x̃2 , ỹ2 ), and (x̃2 , ỹ1 )
are all solved, it is sufficient to ensure that the moves x̃1 , x̃2 , ỹ1 , ỹ2 , ỹ3 occur in
the following order:
I1 (ỹ1 ), I1 (x̃1 ), I2 (ỹ1 ), I1 (ỹ2 ), I2 (x̃1 ), I1 (x̃2 ), I2 (ỹ2 ), I1 (ỹ3 ), I2 (x̃2 ), I2 (ỹ3 ).
So if we can find the correct way to interleave this sequence with the existing
move sequence, we will have a sequence that solves all clusters.
First, we observe that the only important clusters in row ỹ2 and in columns
x̃1 and x̃2 are the ones which the above sequence will solve. So we need only
determine how to correctly interleave the moves for rows ỹ1 and ỹ3 with the
Algorithms for Solving Rubik’s Cubes 25
existing move sequence. We know from the statement of the lemma that the
existing move sequence satisfies the following constraints:
max I1 (x1 ) < min I2 (x1 ) ≤ max I2 (x1 ) < min I2 (x2 ).
x1 ∈X1 x1 ∈X1 x1 ∈X1 x2 ∈X2
So to ensure that each cluster (x1 , ỹ1 ) is solved, we insert the two copies of the
move ỹ1 to satisfy:
max I1 (x1 ) < I1 (ỹ1 ) < min I2 (x1 ) ≤ max I2 (x1 ) < I2 (ỹ1 ) < min I2 (x2 ).
x1 ∈X1 x1 ∈X1 x1 ∈X1 x2 ∈X2
Similarly, we know from the statement of the lemma that the existing move
sequence satisfies these constraints:
So we insert the two copies of the move ỹ3 as follows, to ensure that each cluster
(x2 , ỹ3 ) is solved:
max I1 (x2 ) < I1 (ỹ3 ) < min I2 (x2 ) ≤ max I2 (x2 ) < I2 (ỹ3 ).
x2 ∈X2 x2 ∈X2 x2 ∈X2
To ensure that I1 (ỹ1 ) < I2 (ỹ1 ) < I1 (ỹ3 ) < I2 (ỹ3 ), we note that the above two
constraints do not actually determine the ordering of I2 (ỹ1 ) and I1 (ỹ3 ). So we
can pick an ordering where I2 (ỹ1 ) < I1 (ỹ3 ), which will ensure that all clusters
are solved. t
u
Lemma 14. Given three columns x1 , x2 , x3 ≤ bn/2c, there is a gadget using six
extra rows and two extra columns ensuring that I1 (x2 ) lies between I1 (x1 ) and
I1 (x3 ). As a side effect, this gadget also forces I2 (x2 ) < I2 (x1 ), I2 (x2 ) < I2 (x3 ),
and
Proof. Use a copy of the gadget from Lemma 13 to force I2 (x2 ) < I2 (x1 ) and
I2 (x2 ) < I2 (x3 ). Let y1 , y2 , y3 be three rows not used elsewhere in the construc-
tion. Make each cubie cluster in the set
have the configuration depicted in Fig. 1(d). Make cubie clusters (x1 , y1 ), (x2 , y2 ),
and (x3 , y3 ) remain solved. Mark all of these cubie clusters important. Now we
consider what form an ideal solution could take, given these restrictions.
First, consider the case where I1 (x2 ) < I1 (x1 ) and I1 (x2 ) < I1 (x3 ). Because
of the configurations of cubie clusters (x2 , y1 ) and (x2 , y3 ), we know that
I1 (y1 ) < I1 (x2 ) < I1 (x1 ), I1 (y3 ) < I1 (x2 ) < I1 (x3 ),
I2 (y1 ) < I2 (x2 ) < I2 (x1 ), I2 (y3 ) < I2 (x2 ) < I2 (x3 ).
26 E. D. Demaine, M. L. Demaine, S. Eisenstat, A. Lubiw, A. Winslow
x1 x2 x3 x̃1 x̃2
y1
y2
y3
ỹ1
ỹ2
ỹ3
Fig. 9. A sample of the betweenness gadget from Lemma 14. Important cubies are red
(solved) and blue (unsolved). Unimportant cubies are white. Any ideal solution must
either have I1 (x1 ) < I1 (x2 ) < I1 (x3 ) or I1 (x3 ) < I1 (x2 ) < I1 (x1 ).
Given these constraints, and the requirement that the cubie cluster (x1 , y1 ) re-
main solved, it must be that I2 (y1 ) < I1 (x1 ). Similarly, because the cubie cluster
(x3 , y3 ) must remain solved, it must be that I2 (y3 ) < I1 (x3 ). In order to solve
the cubie clusters (x1 , y3 ) and (x3 , y1 ), it must be that I1 (x1 ) < I2 (y3 ) and
I1 (x3 ) < I2 (y1 ). Therefore
I1 (x1 ) < I1 (x2 ) < I2 (x2 ) < I2 (x1 ) and I1 (x3 ) < I1 (x2 ) < I2 (x2 ) < I2 (x3 ).
Because of the configurations of cubie clusters (x2 , y1 ) and (x2 , y3 ), this sand-
wiching implies that
I1 (x1 ) < I2 (y1 ) < I2 (x1 ), I1 (x1 ) < I2 (y3 ) < I2 (x1 ),
I1 (x3 ) < I2 (y1 ) < I2 (x3 ), I1 (x3 ) < I2 (y3 ) < I2 (x3 ).
To ensure that cubie cluster (x1 , y1 ) still remains solved, we need I1 (x1 ) < I1 (y1 ).
Given the configuration of cubie cluster (x1 , y3 ), we need I1 (y3 ) < I1 (x1 ). To
Algorithms for Solving Rubik’s Cubes 27
ensure that cubie cluster (x3 , y3 ) still remains solved, we need I1 (x3 ) < I1 (y3 ).
Given the configuration of cubie cluster (x3 , y1 ), we need I1 (y1 ) < I1 (x3 ). Thus
So we know that we can place the moves for the extra rows and columns used by
the gadget from Lemma 13. We need only determine where to insert the moves
for the three extra rows added by this gadget.
The constraints given in the statement of the lemma allow for four different
possible orderings of all of the x1 , x2 , x3 moves. We consider each case separately.
1. I1 (x1 ) < I1 (x2 ) < I1 (x3 ) < I2 (x2 ) < I2 (x1 ) < I2 (x3 ). Then we insert the
moves y1 , y2 , y3 so that the following is a subsequence of the move sequence:
y2 , y3 , x1 , y1 , x2 , y3 , x3 , y1 , x2 , y2 , x1 , x3 .
2. I1 (x1 ) < I1 (x2 ) < I1 (x3 ) < I2 (x2 ) < I2 (x3 ) < I2 (x1 ). Then we insert the
moves y1 , y2 , y3 so that the following is a subsequence of the move sequence:
y2 , y3 , x1 , y1 , x2 , y3 , x3 , y1 , x2 , y2 , x3 , x1
3. I1 (x3 ) < I1 (x2 ) < I1 (x1 ) < I2 (x2 ) < I2 (x1 ) < I2 (x3 ). Then we insert the
moves y1 , y2 , y3 so that the following is a subsequence of the move sequence:
y1 , y2 , x3 , y3 , x2 , y1 , x1 , y3 , x2 , y2 , x1 , x3
4. I1 (x3 ) < I1 (x2 ) < I1 (x1 ) < I2 (x2 ) < I2 (x3 ) < I2 (x1 ). Then we insert the
moves y1 , y2 , y3 so that the following is a subsequence of the move sequence:
y1 , y2 , x3 , y3 , x2 , y1 , x1 , y3 , x2 , y2 , x3 , x1
t
u
Proof. We start with a single column rcenter ≤ bn/2c. For each variable xi in φ,
we construct two columns sxi , sxi ≤ bn/2c. We then add a copy of the gadget
from Lemma 14 to ensure that I1 (rcenter ) lies between I1 (sxi ) and I1 (sxi ), for
each value of i. For each clause cj = y1 ∨ y2 ∨ y3 , we add a new column tj . Then
we add a copy of the gadget from Lemma 14 to ensure that I1 (tj ) lies between
I1 (sy1 ) and I1 (sy2 ). Then we add one more copy of the gadget from Lemma 14
to ensure that I1 (rcenter ) lies between I1 (tj ) and I1 (sy3 ).
Note that the additional constraints forced by the gadget from Lemma 14
mean that all of the following inequalities must hold:
We can satisfy all of these constraints by first performing the second move of
rcenter , then performing the second moves of all of the t columns, and finally
by performing the second moves of all of the s columns. The other constraint
imposed by the gadget from Lemma 14 can be satisfied by dividing up the moves
into two sequential stages such that all of the variable, clause, and center moves
are performed exactly once per stage. Hence, the additional constraints enforced
by our gadget do not affect our ability to construct an ideal solution, as long as
φ is a member of 6=-SAT.
To see why this reduction works, suppose that φ is a member of 6=-SAT. We
must convert an assignment to the variables of φ to an ideal solution to the subset
of the Rubik’s Cube constructed above. As noted in the previous paragraph, we
can choose an ordering of all of the second moves that satisfies the gadgets we
have constructed. To arrange the first moves of all of the columns, we pick an
ordering of the columns s corresponding to literals so that I1 (sy ) < I1 (rcenter )
for all true literals y and I1 (rcenter ) < I1 (sz ) for all false literals z. The ordering
of the literals themselves does not matter, and can be picked arbitrarily. This
arrangement ensures that for each xi , we have either I1 (sxi ) < I1 (rcenter ) <
I1 (sxi ), or I1 (sxi ) < I1 (rcenter ) < I1 (sxi ); either way, there will be a way to
correctly arrange the extra columns and rows used by the gadget from Lemma 14.
Algorithms for Solving Rubik’s Cubes 29
We then must pick times for the first move for each column tj . Let cj =
y1 ∨ y2 ∨ y3 be the clause corresponding to the column we are considering.
1. Consider the case where y1 and y2 are both true. Then we pick an arbitrary
location for tj between sy1 and sy2 , so that there is a way to correctly arrange
the extra columns and rows used by the copy of the gadget that ensures that
I1 (tj ) lies between I1 (sy1 ) and I1 (sy2 ). This means that I1 (tj ) < I1 (rcenter ).
Because y1 and y2 are both true, then y3 must be false, and so I1 (rcenter ) <
I1 (y3 ). Hence, there will be a way to correctly arrange the extra columns
and rows used by the copy of the gadget from Lemma 14.
2. Now consider the case where y1 and y2 are both false. Then we pick an
arbitrary location for tj between sy1 and sy2 . Just as before, this satisfies
the gadget from Lemma 14 which forces I1 (tj ) to lie between I1 (sy1 ) and
I1 (sy2 ). This also means that I1 (rcenter ) < I1 (tj ). Because both y1 and y2
are false, y3 must be true, and therefore I1 (y3 ) < I1 (rcenter ) < I1 (tj ). So
once again, the gadget is satisfied.
3. Now consider the case where y1 is true and y2 is false, or vice versa. Then
y3 is either true or false. If y3 is true, then I1 (y3 ) < I1 (rcenter ), and so
we pick the location for I1 (tj ) to be just slightly larger than I1 (rcenter ),
so that I1 (y3 ) < I1 (rcenter ) < I1 (tj ) and I1 (tj ) lies between I1 (sy1 ) and
I1 (sy2 ). Similarly, if y3 is false, then I1 (rcenter ) < I1 (y3 ), and so we pick
the location for I1 (tj ) to be just slightly smaller than I1 (rcenter ), so that
I1 (tj ) < I1 (rcenter ) < I1 (y3 ) and I1 (tj ) lies between I1 (sy1 ) and I1 (sy2 ). In
either case, the location for the first move tj will satisfy both of the gadgets
created using Lemma 14.
So if we have a solution to φ, then we also have an ideal solution.
Now we wish to prove the converse. Suppose that we have an ideal solution.
Then we construct a solution to φ by setting xi to be true if and only if I1 (sxi ) <
I1 (rcenter ). Because of the gadgets that we constructed, we know that all true
literals y have the property that I1 (sy ) < I1 (rcenter ), while all false literals z have
the property that I1 (rcenter ) < I1 (sz ). To see why this works, consider a clause
cj = y1 ∨ y2 ∨ y3 . Assume, for the sake of contradiction, that all three literals
in the clause are true. Then I1 (sy1 ), I1 (sy2 ), I1 (sy3 ) < I1 (rcenter ). Because our
betweenness gadget is working correctly, we know that I1 (tj ) < I1 (rcenter ), as
well. This means that I1 (rcenter ) does not lie between I1 (tj ) and I1 (sy3 ), which
means that our solution could not have been ideal. So our assumption must be
wrong, and not all of the literals in the clause are true. A similar argument shows
that not all of the literals in the clause are false. This means that the clause has
at least one true literal and at least one false literal, and so φ is a member of
6=-SAT. t
u
Lemma 15. Given any c1 × c2 × n Rubik’s Cube configuration, and any cubie
cluster t, the number of short moves affecting that cubie cluster in the optimal
solution is at most 22c1 c2 +8(c1 +c2 ) − 1.
Proof. Consider the subsequence of moves in the optimal solution which affect
t. This should contain all of the long moves, and only those short moves which
rotate one of the two slices in t. For notation purposes, we merge all consecutive
long moves together into compound long moves L0 , . . . , Lk , so that the sequence
of moves is L0 ◦ s1 ◦ L1 ◦ s2 ◦ . . . ◦ Lk−1 ◦ sk ◦ Lk . For convenience, we define
s0 to be the identity function, so that we can write the sequence of moves as
s0 ◦ L0 ◦ s1 ◦ L1 ◦ s2 ◦ . . . ◦ sk ◦ Lk .
We define the following to be the results of performing certain moves:
Assume for the sake of contradiction that there exist i < j such that Seq(0, i) ◦
LSeq(i+1, k) = Seq(0, j)◦LSeq(j+1, k). Composing by the inverse of LSeq(j+
1, k), we obtain Seq(0, i) ◦ LSeq(i + 1, j) = Seq(0, j). Therefore
Hence we can omit the moves si+1 , . . . , sj while still ending up with the cor-
rect configuration for t. This means that there exists a sequence of moves,
shorter than the original, which brings the Rubik’s Cube into the same configu-
ration. But the original sequence was optimal. Therefore, our assumption must
be wrong, and ∀i < j, Seq(0, i) ◦ LSeq(i + 1, k) 6= Seq(0, j) ◦ LSeq(j + 1, k).
In both Seq(0, i) ◦ LSeq(i + 1, k) and Seq(0, j) ◦ LSeq(j + 1, k), the set of
long moves is the same, so the configuration of all cubie clusters other than t
must also be the same. Therefore, the results of those moves must differ in the
configuration of the cubie cluster t. The cubie cluster with the greatest number
of configurations is the cubie cluster which contains the ends of the Rubik’s Cube
(i.e., z = 0 and z = n − 1), because of the additional information given by the
exposed sides of the cube. For that cubie cluster, the total number of different
configurations is ≤ 22c1 c2 ·44(c1 +c2 ) = 22c1 c2 +8(c1 +c2 ) . Each short move affecting t
in the optimal solution must lead to a new configuration of t, and so the number
of short moves must be ≤ 22c1 c2 +8(c1 +c2 ) − 1. t
u
Proof. Every sequence of long moves causes a rearrangement of the cubies in the
Rubik’s Cube. However, there are no long moves which break up the boxes of
cubies of size 1 × 1 × n — each box can be moved or rotated, but the relative
positions of cubies within the box are always the same. There are c1 c2 such
boxes, and each box can be oriented in two ways. This means that there can be
no more than (c1 c2 )! · 2c1 c2 reachable long configurations. We treat these long
configurations as a graph, with edges between configurations that are reachable
using a single long move. If we take a spanning tree of the graph and duplicate
all edges of the tree, then we can find an Eulerian cycle which visits all of the
nodes in the graph. If we start at the identity configuration and move along the
cycle, then we have a path of ≤ (c1 c2 )! · 21+c1 c2 long moves satisfying both of
the above properties. t
u
Proof. Assume, for the sake of contradiction, that the number of long moves
in the optimal solution is greater than (c1 c2 )! · 21+3c1 c2 +8(c1 +c2 ) . Then we can
construct another solution with the same number of short moves as the optimal,
and fewer long moves. Let `1 ◦`2 ◦. . .◦`m be the sequence of long moves satisfying
Lemma 16. Let L be the sequence of long moves in the optimal solution, and let
i be the index such that `i ◦ `i+1 ◦ . . . ◦ `m = L. We choose the sequence of long
moves in our constructed solution to be
This long move sequence has the same result as L. We must also specify how to
interleave the short moves with the long move sequence. For a fixed long move
sequence, the arrangement of short moves for one cubie cluster does not affect
any other cubie cluster. Consequently, if we can correctly interleave the short
moves for one cubie cluster, we can correctly interleave the short moves for all
cubie clusters.
Pick an arbitrary cubie cluster. Consider the subsequence of moves in the
optimal solution which affect said cubie cluster. For notation purposes, we merge
all consecutive long moves together into compound long moves L0 , . . . , Lk , so
that the sequence of moves is L0 ◦ s1 ◦ L1 ◦ s2 ◦ . . . ◦ Lk−1 ◦ sk ◦ Lk . We place
the short moves into the above sequence of long moves starting with sk . Let a
be the index such that `a ◦ . . . ◦ `m = Lk . We insert sk into the kth repetition of
(`1 ◦ . . . ◦ `m ) between `a−1 and `a . This ensures that the sequence of long moves
occurring after k will be equivalent to Lk .
In general, say that we have placed si+1 , . . . , sk in the (i + 1)st through kth
repetitions of (`1 ◦ . . . ◦ `m ). Say we want to place si in the ith repetition. Let b
32 E. D. Demaine, M. L. Demaine, S. Eisenstat, A. Lubiw, A. Winslow
be the index such that si+1 was placed between `b−1 and `b . Let a be the index
such that:
This ensures that the sequence of long moves between si and si+1 will be:
Hence, if the number of long moves in the optimal solution is greater than
(c1 c2 )! · 21+3c1 c2 +8(c1 +c2 ) , we can create a solution with the same number of
short moves and fewer long moves. This means that we have a contradiction. t u
Proof. By Lemma 17, we know that the total number of long moves in the
optimal solution is at most (c1 c2 )! · 21+3c1 c2 +8(c1 +c2 ) , which is constant. We also
know that there are a total of c1 + c2 possible long moves. Hence, the total
number of possible sequences of long moves is constant, so we can enumerate all
of these in time O(1).
For each of the sequences of long moves, we want to find the optimal solution
using that sequence of long moves. Because the long moves are fixed, we can
calculate the short moves for each cubie cluster independently. To calculate the
short moves for some fixed cubie cluster, we note that between two sequential
long moves, there are at most four different ways to rotate each of the two slices
in the cubie cluster, for a total of at most sixteen possible combinations of short
moves.
1+3c1 c2 +8(c1 +c2 )
For a given cubie cluster, we have to consider ≤ 161+(c1 c2 )!·2
possible combinations. This is constant, so we can try all possibilities to see if
they solve the cubie cluster. We can pick the shortest of those. If we perform
this operation for all cubie clusters, we will have an optimal solution for this
particular sequence of long moves. If we calculate this for all sequences of long
moves, then we can pick the overall optimal solution by taking the sequence of
minimum length. t
u
Our results leave several questions open. The most obvious questions concern
the NP-hardness result: whether it can be modified to show the NP-hardness of
optimally solving the whole n × n × 1 Rubik’s Cube, and whether it can be fur-
ther modified to show the NP-hardness of optimally solving the whole n × n × n
Rubik’s Cube. The other questions concern approximation algorithms. In par-
ticular, is there a constant-factor polynomial-time approximation algorithm for
finding an approximately optimal solution sequence from a given configuration?
The analogous question for the n2 − 1 puzzle has a positive answer [21]. The
parallelism techniques we introduced for the diameter results seem to be central
to developing such an approximation algorithm.
References
1. World Cube Association. Official results. http://www.worldcubeassociation.org/
results/, 2010.
2. Stephen A. Cook. Can computers routinely discover mathematical proofs? Pro-
ceedings of the American Philosophical Society, 128(1):40–43, 1984.
3. James R. Driscoll and Merrick L. Furst. On the diameter of permutation groups.
In Proceedings of the 15th Annual ACM Symposium on Theory of computing, pages
152–160, 1983.
4. Andy Drucker and Jeff Erickson. Is optimally solving the n × n × n Ru-
bik’s Cube NP-hard? Theoretical Computer Science — Stack Exchange
post, August–September 2010. http://cstheory.stackexchange.com/questions/783/
is-optimally-solving-the-nnn-rubiks-cube-np-hard.
5. Shimon Even and Oded Goldreich. The minimum-length generator sequence prob-
lem is np-hard. Journal of Algorithms, 2(3):311–313, 1981.
6. Frank Fox. Spherical 3x3x3. U.K. Patent 1,344,259, January 1974.
7. Merrick Furst, John Hopcroft, and Eugene Luks. Polynomial-time algorithms for
permutation groups. In Proceedings of the 21st Annual Symposium on Foundations
of Computer Science, pages 36–41, 1980.
8. Michael R. Garey and David S. Johnson. Computers and Intractability: A Guide
to the Theory of NP-Completeness (Series of Books in the Mathematical Sciences).
W. H. Freeman & Co Ltd, first edition edition, January 1979.
9. Wiliam O. Gustafson. Manipulatable toy. U.S. Patent 3,081,089, March 1963.
10. Terutoshi Ishige. Japan Patent 55-8192, 1976.
11. Mark R. Jerrum. The complexity of finding minimum-length generator sequences.
Theoretical Computer Science, 36(2–3):265–289, June 1985.
12. Graham Kendall, Andrew Parkes, and Kristian Spoerer. A survey of np-complete
puzzles. International Computer Games Association Journal, 31(1):13–34, 2008.
13. Udo Krell. Three dimensional puzzle. U.S. Patent 4,600,199, July 1986.
14. Leslie Le. The world’s first 12x12x12 cube. twistypuzzles.com forum post, Novem-
ber 2009. http://www.twistypuzzles.com/forum/viewtopic.php?f=15&t=15424.
15. Seven Towns Ltd. 30 years on. . . and the Rubik’s Cube is as popular as ever. Press
brief, May 2010. http://www.rubiks.com/i/company/media library/pdf/Rubiks%
20Cube%20to%20celebrate%2030th%20Anniversary%20in%20May%202010.pdf.
16. Pierre McKenzie. Permutations of bounded degree generate groups of polynomial
diameter. Information Processing Letters, 19(5):253–254, November 1984.
17. Larry D. Nichols. Pattern forming puzzle and method with pieces rotatable in
groups. U.S. Patent 3,655,201, April 1972.
34 E. D. Demaine, M. L. Demaine, S. Eisenstat, A. Lubiw, A. Winslow