Annals of Discrete Mathematics 9 (1980) 13-20 @ North-Holland Publishing Company
THE HUNGARIAN MAGIC CUBE PUZZLE Uldis CELMINS Department of Combinatorics and Ont. N2L 3G1, Canada
Optimization, University of
Waterloo,
Waterloo,
The puzzle is a mechanical device seemingly consisting of 27 little cubes arranged in a large 3 ~ 3 x cube. 3 In its initial configuration each face of the large cube is coloured a different colour. Thus each little cube has 0, I , 2 or 3 of its faces coloured. An arbitrary configuration is obtained by breaking up the large cube and reassembling it so that each little coloured face remains visible. We may also picture the large cube in three different ways as 3 layers of 9 cubes each. The device is constructed to allow face-turns only. by which is meant a 90" rotation of an outside layer with respect to the other two layers. An accessible configuration is one obtainable by a sequence of face-turns. We demonstrate (a) a method for deciding whether an arbitrary configuration is accessible or not (there are 12 orbits or classes of configurations). (b) a procedure for obtaining the initial configuration from any accessible one by face-turns. (Current best is at most 100 turns.) We generalize the above to certain cubic maps.
1. introduction and definitions Consider a cubic map M obtained by properly embedding a graph in an orientable surface. The boundary of each region is a simple circuit and thus gives a face of M. In the case of the puzzle the underlying map is the planar embedding of the cube. By colouring the faces we induce a labelling of the edges and vertices of M. These induced labels become the visible colours of the edge-cubes and vertex-cubes respectively. To work with the puzzle on paper we move edge-cubes from edge to edge and vertex-cubes from vertex to vertex on the map. A face-turn generates a particular cyclic permutation of the edge-cubes (resp. vertex-cubes) on that face. In the initial configuration we say each edge-cube and vertex-cube is fixed in position. After several face-turns a cube may return to its position o n M but might no longer be fixed. An edge-cube might be flipped and a vertex-cube might be twirled clockwise or counterclockwise. Thus, if M has v vertices and e edges the number of arbitrary configurations is u ! e ! 3"2'. A turn diagram (see Fig. 1) consists of the map M and a collection of sequentially numbered arrows placed alongside edges in the faces of M. Each arrow is meant to indicate a particular face-turn. We show the result of performing the indicated sequence of turns, called a move, by a vertex-cube permutation diagram and an edge-cube permutation diagram. For each cube that is displaced 13
.
14
U. Celttiins
an arc is formed by piecing together the arrows of the turn diagram. These arcs are then simplified to display in a concise manner the effect of the move. The resulting permutation diagram may therefore not contain enough information to invert the move. Since it is easy to draw a permutation diagram for any particular configuration, the central problem in obtaining an initial configuration from an accessible one is this loss of information. These permutation diagrams reveal the cycle structure and hence parity of the edge and vertex permutations generated by a move. In addition each such cycle is said to have a nature. If we take a k-cycle in the edge (resp. vertex)-cube permutation and perform the move that creates this cycle k times, then each edge-cube (resp. vertex-cube) returns to its original position. However. all edge cubes will be flipped or none will be flipped (resp. all vertex-cubes will be twirled clockwise, or all twirled counterclockwise. or none twirled at all). Hence an edge-cube (resp. vertex-cube) cycle is named a flip-cycle or a non-flip-cycle (resp. clock-twirl-cycle, counter-twirl-cycle, non-twirl cycle). We speak of the natured cycle structure of a configuration. We say an edge-cube permutation is non-Pip according as t h e number of its flip-cycles is even or odd. We say a vertex-cube permutation is non-twirl, clocktwirl, or counter-twirl according as the number of its clock-twirl cycles minus the number of its counter-twirl cycles is congruent to 0, 1 or 2 (mod 3).
2. The visual rule and a theorem on accessible configurations
In this section we present results which are concerned with both the edge-cube and vertex-cube permutations. Since the development of the theory is similar, we may sometimes concentrate on the vertex-cube permutations. To each cycle there corresponds a closed directed curve on the surface containing the map. For edge-cube permutations the direction is irrelevant and is dropped. The curve is obtained by piecing together the arcs of the permutation diagrams as in Fig. 1. Notice that the nature of the cycle can be determined from the curve and is independent of the number of vertex-cubes or edge-cubes permuted by that cycle. Consider a closed curve corresponding to a cycle in a vertex-cube permutation. In what follows, we assume the curve separates the surface into two regions, “inside” and “outside”. We adopt the convention that the curve is directed clockwise around the inside region. Suppose we further assume that the curve does not intersect itself and that t h e inside region is but a single face F. If an edge bounds F but is outside the curve. that indicates a turn of face F. A vertex-cube which is displaced by this face-turn has a face in F and as indicated in Fig. 2 this little face remains in F. If an edge bounds F but is inside the curve, that indicates a turn of a face F‘ different from F. The vertex-cube which is displaced by this face-turn has a face in F and as
15
The Hungarian Magic Cube Puzzle
piJ 3
Turn diagram for primitive B.
Vertex-cube permutation diagrams, initial and simplified.
The arc from vertex x to vertex y indicates that the vertex-cube that is displaced from x to y moves as if it has been turned clockwise by face 6 and then clockwise by face 4.
Curve containing no vertices. Nonflip.
Edge-cube permutation diagrams, initial and simplified.
Directed curves. C , is clock-twirl and C , is countertwirl.
Permutation diagrams for (primitive €3)’. The four displaced vertex cubes return to their positions. but two are twirled clockwise and two counter-clockwise as indicated. We use the “wiggly” arc in the edge-cube permutation diagram as a shorthand for a displacement with flip.
Permutation diagrams for (primitive B ) 3 . The edge-cubes are now fixed in position. We use the “wiggly” arc in the vertex-cube permutation diagram to denote the only displacement between adjacent vertices that cannot be given by a single face-turn.
Fig. 1. Explanation of notation.
non-twirl cycle
counter-twirl cycle
clock-twirl cycle
Fig. 2. The visual rule.
non-twirl cycle
16
U . Celmins
indicated in Fig. 2, this little face turns away from F in a counter-clockwise direction. From here we proceed by induction on the number of faces in the inside region to obtain the following visual rule:
Lemma 1. I f the curve is non-self-intersecting and if it separates the surface into two regions and is directed clockwise around the inside region, the cycle in the uertex-cube permutation is non-twirl, counter-twirl, or clock-twirl according as the number of edges inside the curve is congruent to 0, 1 or 2 (mod 3). We also have: A cycle in the edge-cube permutation is a flip-cycle i f fthe number of vertices of the map inside the curue is odd.
P and P are non-twirl P'
P
vertex-cube permutation diagrams
arc-decomposition
vertex-cube permutation diagrams
arc-decomposition
Q and Q' are coun ter-twirl
PO and P'Q' are counter-twirl
@ PQ
P'Q'
vertex-cube permutation diagrams
lg/
arc-decomposi tion A
Simplified vertexcube permutation diagrams for PQ and P'Q' PQ
Fig. 3. Lemma illustrations.
The Hungarian Magic Cube Puzzle
17
The arc-decomposition (see Fig. 3 ) of a vertex-cube (resp. edge-cube) permutation is obtained by taking each arc alongside k 2 1 edges and drawing it as k arcs, each alongside one edge. It is possible to apply the visual rule to self-intersecting curves (see Fig. 3, Q and Q’) because of the following lemma:
Lemma 2. Two vertex-cube (resp. edge-cube) permutations with the same arcdecomposition have the same nature. In addition we have these lemmas: Lemma 3. I f move P has the same arc-decomposition of both the vertex-cube and edge-cube permutations as move P’ and if moves Q and Q’ are also related in this way, then the product moves PQ and P’Q’ can also be so related. (PQ denotes move P followed by move Q, see Fig. 3 ) . Lemma 4. If the vertex-cube (resp. edge-cube) permutation of moves P and Q contains just one cycle of k > 1 vertex-cubes (resp. edge-cubes) and these two cycles (one from P and one from Q ) have no vertex-cubes (resp. edge-cubes) in common, then the nature of the vertex-cube (resp. edge-cube) permutation of PQ is the “sum” of the respective natures of P and Q. Lemmas 2, 3 and 4 are used to prove the following lemma:
Lemma 5. Given any two moves P and Q, the nature of the vertex-cube (resp. edge-cube) permutation of PQ i s the “sum” of the natures of the vertex-cube (resp. edge-cube) permutations of P and Q. Given a Hungarian Cube Puzzle in an arbitrary configuration (or a general map puzzle) we first draw the permutation diagrams that would yield the initial configuration. We can then determine if this configuration is accessible or not by the following theorem:
Theorem 6. For any map M and initial face colouring, an arbitrary configuration is accessible only i f (i) the parities of the edge-cube and vertex-cube permutations are the same, (ii) the edge-cube permutation is non-flip, (iii) the vertex-cube permutation is non-twirl. Part (i) follows from t h e fact that each face-turn yields a k-cycle in both the vertex-cube and edge-cube permutations. Parts (ii) and (iii) are a consequence of Lemma 5 and the fact that each
18 turn diagrams
vertex-cube permutation diagrams
edge-cube permutation diagrams
Basic vertex-cube permutation moves A and B. Move A followed by the inverse of B causes two adjacent vertex-cubes to he twirled: one clockwise, the other counter-clockwise.
A:
)=%()-( -1- 3-
) k %
Primitive moves A and B. To solve the general orientable surface map puzzle we use the primitive moves first to fix the edge-cubes in position and then the basic vertex-cube moves to fix the vertex-cubes. Adjacent edge-cubes can be flipped by following B with the mirror-image in the indicated axis. The number of turns required is at most a quadratic polynomial in the number of vertices. Fig. 4. General moves for arbitrary maps
face-turn yields a non-twirl cycle of the vertex-cube permutation and a non-flip cycle of the edge-cube permutation. The theorem partitions the arbitrary configurations into 12 classes (or 24 if each face is bounded by an odd number of edges). The moves given in Fig. 4 show the converse of the theorem to be true provided M is of girth at least 4 and provided no two faces have more than one edge in common. (This last condition excludes, for example, the three toroidal embeddings of the cube.)
19
The Hungarian Magic Cube Puzzle
3. Solving the cube puzzle We conclude with some remarks on obtaining the initial configuration from any accessible one for the Hungarian Magic Cube Puzzle, that is to say, on solving the cube. In giving demonstrations, we use a layer by layer approach that requires the memorization of five moves and needs no consultation of tables. This form may take as many as 1.50 face-turns although 100 is often the case. When tables are consulted the total number of face-turns can always be reduced to about 100. First, the edge-cubes and then the vertex-cubes of the first layer are fixed in position (this exercise is left to the reader). Then, the two moves in Fig. 6 are used to fix the edge-cubes of the middle and last layers. Finally the basic vertex-cube permutation moves A and B of Fig. 4 are used to fix the vertex-cubes of the last layer. The fifth move to memorize is the use of A and B together to twirl vertex-cubes, one cube clockwise and one counter-clockwise. It seems to be desirable to have short moves that produce small changes in the cube. This author knows three &turn moves that give a 3-cycle of vertex-cubes only, permuting no edge-cubes at all. A and B are given in Fig. 4 and C is
Example 1. A 2-nesting of the basic vertexcube permutation move B. (i) turn faces I , then 2 counterclockwise. (ii) Apply move B where indicated (see Fig. 4). (iii) Turn faces 2. then 1 clockwise. The resulting 12 turn move is given at the right. The edge-cubes remain fixed in position.
A 2-nesting of the primitive B obtained by first turning face 1 clockwise and face 2 counter-clockwise
The primitive B in another position.
(first turn face
3 clockwise)
The product move of the above two moves (12 face-turns). We use “ X ’’ to indicate flips of edge-cubes.
A I-nesting of the product move (14
Fig. 5. Nesting of moves.
turns)
U. C h i n s
20 \
\
Use this move and its mirrorimage in the indicated axis to fix edge-cubes of the middle layer. I
I
\\
Use this 1-nesting of the primitive A to fix the edge-cubes of the last layer in position. This move with its mirror-image in the indicated axis will flip adjacent edge-cubes.
Fig. 6 . Some other moves for the cube puzzle.
obtained by reversing the directions of face-turns 3 and 7 in move B. We also have two %turn moves that permute three edge-cubes only and a &turn move that gives a 5-cycle of edge-cubes only. Of the preceding moves the ones with 8 turns we term basic. In addition we make use of two primitive moves of four face-turns each (Fig. 4). both of which permute 3 edge-cubes and two pairs of vertex-cubes. A k-nesting of a move X is a new move Y , consisting of k face-turns followed by the move X , followed by the inverse of the k face-turns. It is not hard to show that the natured cycle structures of X and Y are the same. We thus say that moves X and Y are similar. We find that all 15 non-twirl 3-cycles of vertex-cubes can be obtained by a k-nesting of move C where k is at most 4. All 27 non-flip 3-cycles of edge-cubes can be obtained from another basic move by k-nesting with k at most 4. The author has tabulated these and the 1- and 2-nestings of the primitive moves. Fig. 5 contains some examples. This material suggests two algorithms for solving the cube: use the primitive moves or otherwise fix all the edge-cubes (resp. vertex-cubes) in position and then use the basic vertex-cube permutation moves (resp. edge-cube) and their k nestings to fix the remaining cubes in position. The number of face-turns required can be reduced to less than 100 by careful use of tables. We conjecture that all configurations similar to a given one can be obtained by a k-nesting of it, where k is small, perhaps at most 10. This might lead to the following procedure: (i) given an accessible configuration, make several turns to obtain another configuration similar to a catalogued one. (ii) compute the k-nesting of the catalogued configuration that is needed to solve the cube. Since presenting an earlier version of this paper in Montreal in June 1979, I have heard of several people who have worked on the puzzle, among them David Singmaster and John Conway in England, Ervin Bajmoczy in Hungary and Don Taylor in Australia. I wish to thank Frank Allaire for giving me my first Hungarian cube and for the many ensuing hours of enjoyment.