Twenty-Five Moves Suffice for Rubiks Cube
How many moves does it take to solve Rubik's Cube? Positions are known that require 20 moves, and it has already been shown that there are no positions that require 27 or more moves; this is a surprisingly large gap. This paper describes a program th…
Authors: Tomas Rokicki
Tw en t y-Fiv e Mo v es Suffice fo r Rubik’s Cub e T omas Rokic ki Abstract How many mov es do es it take to solve Rubik’s Cube? Positions are known that require 20 mov es, and it has already been shown that there are no p ositions that require 27 or mo re moves; this is a surpris ing ly large gap. This pap er desc r ibe s a pro g ram that is able to find solutions of length 20 or les s at a rate o f more than 16 million po sitions a second. W e use this progra m, alo ng with some new ideas a nd incremental improv ements i n other techniques, to show t hat there is no po sition that r equires 26 moves. 1 In tro duction The Rubik’s Cube is a s imple, inexpens ive puzzle with only a handful of moving par ts, yet so me o f its simplest prop erties remain unknown more than thirty years a fter its in tro duction. One of the most funda- men tal questions remains unsolved: how many mov es are require d to so lve it in the worst case? W e consider a s ing le move to b e a turn of any face, 90 degr ees or 180 deg rees in any direction (the ‘fa c e turn metric’). In this metric, there are more than 36 ,000 distinct po sitions known that require at least t wen t y moves to solve[8 ]. No pos itions are yet known that require t wen ty-one moves. The b est theoretical a pproaches and co mputer sear ches to date hav e only b een a ble to prov e there are no po sitions that requir e more than t wen ty-six moves[3 ]. In this pap er, we prove that all p ositions can be solved in tw ent y-fiv e or fewer moves. W e prov e this new result by separating the cube space into tw o bil- lion sets, each with 20 billio n elements. W e then di- vide our attention b etw een finding an upper b ound on the distance of p ositions in s pecific sets, and co m- bining those results to calculate an upper b ound on the full cub e space. The new co nt ributions o f this pap er are : 1. W e extend Ko c iemba’s near-o ptimal solving a l- gorithm to c o nsider six transformations of a pa r- ticular p osition simultaneously , so it finds near- optimal p ositions more quickly . 2. W e conv ert his s olving a lgorithm into a set solver that solves billions of p os itions at a time. 3. W e show how to eliminate a large num b er of the sets from cons ider ation, b eca use the p ositions in them o nly o ccur in conjunction with p ositions from o ther sets. 4. W e combine the three contributions ab ov e with some simple gr eedy a lgorithms to pick s e ts to solve, and with a fair a mount of computer p ow er, we a ctually run the sets, com bine the res ults, and prov e that every p osition in the cub e can be solved in 25 moves o r less. 2 Colors, Mo v es, and the Size of Cub e Sp ace The Rubik’s cube app ears as a s tack of 27 smaller cubes (cubies), with ea ch face of the cubies colored one of six colors. Of these 27 cubies, se ven form a fixed frame ar ound whic h the o ther t wen ty mov e. The seven that form the fixed frame a re the cen ter cubies on ea ch face a nd the central cubie. Each mo ve on the cub e consis ts of grabbing the nine cubies that form a full face o f the larger cub e, and rotating them as a g roup 90 o r 180 degrees around a ce n tral axis shared by the main cube a nd the nine cubies. Ea ch mov e maintains the s e t of fully- visible cubie faces. The eight cor ner cubies each al- wa ys hav e the same set of three faces vis ible, and the t welv e edge cubies each a lwa ys hav e the same set of t wo faces visible. W e will frequently use the ter m ‘corner’ to mean ‘corner cubie’, a nd ‘edge’ to mean ‘edge cubie’. Page 1 In the solved p os ition, ea ch face o f the main cub e has a single color. By co nv en tion, we ass o ciate these colors with their orientation on the so lved cube: U(p), F(ront) , R(ight), D(own), B(ack), and L(eft). Ea ch mov e that uses a a 9 0 degree clo ckwise twist is s pec- ified by just sp ecifying the face with no suffix; ea ch mov e that uses a 90 degr ee co un terclo ckwise t wist is sp e c ified with the face follow ed by a prime symbol ( ′ ), and each mov e that uses a 18 0 deg r ee twist is sp ecified with the face follow ed b y the digit 2. So a clo ckwise quarter turn of the r ight face is represented b y R, and the move sequence R2L2U2D2F2B2 genera tes a prett y pattern k nown as Pons Asinorum . There are a total of eig h teen different mov es; we define this set b y S . (By conven tio n, a clo ckwise turn is sometimes written with a ‘+’ or ‘1’ suffix and a counterclo ckwise turn is s o metimes written with a ‘3’ suffix.) The cor ner cubies may be p ermuted ar bitrarily , as may the edge cubies, except that the parity of the p er- m utations of the edg e and corner p ermutations must match. This contributes a fac to r of 12!8! / 2 tow ard the total num b er of reachable positio ns . Every corner cubie has exactly one face with either the U or D color. W e define the default o rientation for the c o rner cubies to b e that where the U or D face is on the who le - cube u or d face; the co rner cubies may also b e t wisted 1 20 deg rees clo ckwise or counterclock- wise with r e s pec t to this default or ientation (loo king tow ard the center of the cub e). Note that these ori- ent ations fo r each cubie ar e preserved by the mov es U, D, R2, L2 , F2, B2, but not b y the mov es R, L, F, or B. This corner cubie or ient ation is fully arbitrary , except that the sum of a ll the twists for all the corner cubies must be a m ultiple of 36 0 degrees. These co r - ner orientations contribute an additional 3 8 / 3 factor tow ard the total num b er of reachable positio ns . W e define the default edge orientation to b e that orientation in the solved state of the cube that is pre- served by the moves U, D, R, L, F2 , B2 (but changed b y F and B). Each edge is either flipp ed from this orientation or no t; the count of flipped e dg es must be even. These edge orientations co nt ribute an addi- tional 2 12 / 2 factor tow ard the total n umber of r e ach- able p ositions. The total num be r of reachable p ositions , and th us, the size, of the cub e group, is the pro duct o f these factors, which is ab out 4.33E1 9. W e call the set of reachable po sitions G . F or ea ch o f these p os itions, an infinite num b er of mov e sequences obtain that po - sition. W e define the distanc e of a po sition p ( d ( p )) to b e the sho rtest length of any mov e sequence that obtains that po sition. W e define the dis ta nce of a set of p ositions to b e the maximum of the distances o f all the p os itio ns in that set. As a conv ention, we will deno te the successive a p- plication of tw o move seq uence s by co ncatenation. W e will also denote the application of a sequence to a po sition, or set of pos itio ns , b y co ncatenation of the po sition a nd the sequence. 3 Symmetry The Rubik’s cub e is highly symmetrical. Ther e is no distinction among the fac e s ex cept for the colo r; if w e were to toss the cube in the air and catch it, the cub e itself remains the same; only the colo r co rresp onding to the u face , the r face, and so on changes. Indeed, b y tossing the cub e, catching it, and noting the colors on the v a rious faces in the new or ien tation, we can enu mera te a total of 24 differen t w ays we can o r ient the cube, each with a distinct mapping of color s to U, F, R, D, B, and L face s . Specifically , there are six different color s the up face can hav e, and for e a ch of those six color s, there are four colo rs po s sible for the front face. These t wo face c olors fully define the orientation of the nor mal physical cub e. If we p eer in a mirror while p erfor ming this exp er- imen t, we notice that our alter-eg o holds a cub e with mirror-r eversed orientations; these mirror- reversed orientations present an additional 24 p ossible map- pings from co lors to o r ient ed faces. W e further notice that whenever we do a c lo ckwise mov e, our alter ego do es a counterclockwise move. If we c ho ose a canonical color representation, then each of these 48 orient ations is a p ermutation of the cube co lo rs. W e call this set of color per m utations M . If a particular cub e p os ition p is obtained by a mov e sequence s , we can obtain fully cor resp onding po sitions by applying o ne of the 48 color p ermuta- tions (say , m ), p erforming the seq uence s , and then applying the inv erse p ermutation of m . The resulting po sition shares many prop erties with the o riginal o ne (espec ia lly , fo r us, distance). If w e rep eat this o per a- tion for all 48 p ermutations in M , we will o btain 48 po sitions. These p ositions are not a lways unique, but for the v as t ma jority of cube p o s itions they will be. Using this form of symmetry , we can reduce many explorations of the cub e space by a factor o f 48. Each cub e p osition has a single specific in verse p o- sition. If a p osition is r eached by a mov e sequence s , then the inv erse p os ition is rea ched by inv erse move sequence s ′ . T o inv ert a move se q uence, you reverse it and inv ert each mov e; the face r emains the same, but clo ckwise b ecomes counterclo ckwise a nd vice versa. The set of symmetrica l positions of the in verse of p o- sition p is the same as the in verses of the symmetri- cal pos itio ns of p . Some prop erties of a po sition are Page 2 shared by its inv erse p osition (sp ecifically , distance). W e ca n partition the cub e space in to symmetry- plus-inv erse reduced sets by combining each p osi- tion with its symmetrical po sitions and their inv erses; there are o nly 4.51E 17 suc h sets. 4 Calculating the Diameter W e are prima rily interested in finding the maximum of the distance for a ll p ositions ; this is known as the diameter of the g r oup. One technique fo r this is to enumerate all p ositions, and optimally s olve each. Pr actical o ptimal solvers for Rubik’s cube have been av ailable for some time[4]; they t ypically aver- age ab out 15 minutes for e a ch optimal solution (with great v a riance b oth among progr ams and among po - sitions). If we were to use such a prog ram to solve the r e duced set of 4.51E 17 po sitions, with to day’s hardware, w e w ould require mor e than three million computers for mo re than three million years. W e kno w, how ever, that some p ositions require a t least tw en ty moves. The first such p o s ition found is ca lled sup erflip ; it has every cubie in the cor rect place, all corner s cor rectly oriented, and all e dges flipped[7]. Herb ert Ko ciemba devised a n alg orithm to quic kly find reas onably short but not necessarily optimal so lutions to arbitrar y pos itions. That pro- gram (slightl y improv ed as we shall describ e) ca n find mov e sequences of length tw ent y o r less at a ra te o f ab out 24 0 p ositions p er second (sub ject to the con- dition that there is suc h a sequence; no exceptions hav e b e e n found yet). Even with this kind of sp eed, proving all 4 .51E1 7 p ositio ns would require more than seven thousand co mputers for more than seven thou- sand years. All hop e is not lo st. T echnology marches onw ard; when we get to the point we can so lve nine hundred million po sitions a s e cond, we will need only four com- puters fo r four years to finish the pro o f. In the mea n- time, w e can come up with b etter tec hniques to refine the upp er bo und, and improve our tec hniques. 5 Ko ciem ba’s Algorithm Several techn iques hav e b een used to find an upp er bo und on the diameter of the cub e group. Thistle- waite gav e a four-stag e algor ithm that requires a max- im um of 52 mov es. Herber t Ko ciemba improv ed this to a n a lgorithm that requires a maximum of 29 moves (as shown by Mich ael Reid[6]). Our w or k is ba sed on Ko ciemba’s a lgorithm, so we will describ e it a bit further here. Ko ciemba himself has a m uch more de- tailed explanatio n on his web site[2 ]. In 20 06, Silviu Radu reduced the upper b ound to 27[5], and in 2 007 Kunkle and Co op erman re duced it to 26 [3]. Ko ciemba’s algor ithm identifies a subset of 2 0 bil- lion po sitions, called H . Reid showed that every p osi- tion in this subset is solv able in at most 18 mov es, and further that every cube p osition is a t most 12 moves from this subset. Phase one finds a mov e sequence that takes an ar bitrary cub e p os ition to s o me p osition in the s ubset H , and phas e tw o finds a mov e sequence that takes this new p osition to the fully solved state. T o descr ib e this subset, w e will introduce s ome new terminology . A c ubie b elongs in a par ticular place, if it is in that place in the solved cube. Thus, all cubies that hav e so me face colo red u belong in one o f the top nine cubies. The middle lay er consis ts of the nine cubies be tw een the top a nd b ottom lay ers; o nly four of these cubies (edges a ll) mov e. The subse t H is comp osed of all patterns that hav e the following characteristics: 1. All corners and edges are pr op erly or ient ed. 2. The edge cubies that belo ng in the middle lay er are lo ca ted in the middle lay er. The num b er of po sitions for which these conditions hold are the p ermissible per mutations of the corners, the top and b ottom e dges, and the middle edges, with the condition tha t the parity b etw een the edge p er- m utation and the co rner p ermutation must match. This is thus 8!8!4 ! / 2 or 19.5 billion p ositions. These characteristics ar e preserved by the mov es U, U2, U ′ , D, D2, D ′ , R2, L2, F2 , B2, which we call the set A . F urther, these mov es suffice to tr ansform every p o sition in H to the solved s tate. (This is a nontrivial result, but it can easily b e shown by brute force enumeration.) F or almost a ll p ositions in H , the shortest move sequence cons is ting only of mov es from A is the sa me length as the shortest mov e sequence consisting only of moves fro m S , as shown in T able 1. F urther, the worst case is 1 8 in bo th cases . Because the defining characteristics of this set treat the U and D faces differently than the L, R, F, and B faces, all 48 symmetries of the cub e cannot b e used; how ever, 16 can be used. Thus, a fter reducing b y symmetry , and using tw o bits p er entry , it is po ssible to stor e a dista nce table for the entire set H in only ab out 300MB of memory . T o determine a sequence that takes a p osition in H to the solved p osition, sim- ply lo ok up the distance for the current p o sition in the la r ge table. If it is not zero, try each of the 10 mov es in A to find a p o sition that is closer, and make that mov e. Repea t until the cub e is solved. Page 3 d mov es in S mov es in A 0 1 1 1 10 10 2 67 67 3 456 456 4 3,079 3,079 5 20,076 19,9 48 6 125,21 8 123,07 4 7 756,09 2 736,85 0 8 4,331,1 24 4,185,118 9 23,639 ,531 22,630 ,733 10 122,74 9,840 116,767,8 72 11 582,01 7,108 552,538,6 80 12 2,278,2 15,506 2,176,3 44,160 13 5,790,8 41,966 5,627,7 85,188 14 7,240,7 85,011 7,172,9 25,794 15 3,319,5 65,322 3,608,7 31,814 16 145,10 7,245 224,058,9 96 17 271,112 1,575,6 08 18 36 1,352 19,508 ,428,80 0 19,508 ,428,80 0 T able 1: The num b e r of po sitions in H at a given distance using mov es fro m S and mov es fro m A ; the n umbers are striking ly similar. The r emaining problem is how we c a n tr ansform a n arbitrary cube position into a p osition in H in 12 or few er moves. T o illustrate how this can b e done, we describ e a way to r e la b e l the cub e so that all po sitions in H hav e the same app eara nce , and a ll p ositio ns not in H hav e a different app eara nce. Consider an ar bitrary p osition p . T o b e in H , the per mu tations of the corner s ar e irrelev a n t; only the orientation matters. T o r epresent this, we remove all colored stic kers fro m the cor ners, r eplacing the stic k- ers colore d U or D with U and leaving the other faces, say , the underlying black plastic. (T o make it easy to follow, we a lso replace the D stick er in the center of the b ottom face with U.) All corner cubies are now in terchangeable, but we hav e sufficient infor mation to note the o r ient ation of the co r ners. The p er mutation o f the middle edges do es not mat- ter either, but they must lie in the middle lay er and be oriented correctly . W e thus remove the c o lored stick ers from four edge cubies that b elong in the mid- dle lay er, re pla cing the F and B color s with F a nd leaving the L and R c o lors as bla ck. (W e als o replace the B center stick er with F for co nv enience.) The p ermutations o f the top and b ottom edges also do es no t matter; for these w e do the same colo r change we did for the corners (U and D get turned in to U, a nd the other four colors ge t remov ed). With this transformation, all p ositions in H get turned int o the same solved cub e: eig h t corners , ea ch with a U s ticker on either the up or down face; four middle edges, ea ch with a F stic ker on either the front or back face; eight top/ bo ttom edges, each with a U stick er on the top or b ottom face. Every pos ition not in H has a different a ppea rance. This relab eled puzzle has a muc h smaller s ta te space than the full cube space. Specifica lly , the space consists of 3 8 / 3 corner orientations multiplied b y 2 12 / 2 edge orientations multiplied by 12 4 wa ys to distribute four middle edges among tw elve edge po sitions, for a total of 2.22E9 p ositions. W e call this se t of p ositions R . With 16 wa ys to reduce this b y symmetry a nd using only tw o bits p er state, a full distance table is easy to fit in memor y , and the full state space can b e explored easily . W e shall call this relab eling pro cess r ; it takes a p osition in G and transforms it into a po s ition in R . Ko ciemba’s algor ithm, then, is to tak e the orig inal po sition, call it p , co mpute r ( p ), the rela b e ling ; solve the relab eled puzzle with some seq uence a ∈ S ∗ , ap- ply those moves to an origina l cub e yielding pa which lies in H , and then finish the so lution with ano ther sequence b ∈ A ∗ such that pab is the solved cub e. The final s olution sequence is ab . Ko ciemba’s alg o rithm splits the problem in to tw o roughly equal s ubproblems, each of which is easy to exhaustively explore, us ing a lo okup table that fits in memory , yielding a fair ly go o d solution to the muc h larger problem. This algorithm can find a solution of distance 29 or less almos t instan taneo us ly (in well under a millisecond). This defines an upp er b ound on the worst-case p o s ition distance. Ko ciemba extended this a lgorithm for another pur- po se: to quickly find near - optimal solutions for a given p osition. He prop osed finding many phas e 1 solutions, starting with the shortest and increa s ing in leng th, and for each finding the shortest pha se 2 solution. By considering dozens, thousands, or even millions of such se q uences, he has found that in prac- tice nearly o ptimal s olutions ar e found very quickly . Given an input which is the initial cub e po sition de- noted by p , his algor ithm is g iven as Alg orithm 1. The algor ithm can either run to completion, o r it can be terminated by the user or when a solution of a desired length is attained. In Ko ciemba’s algorithm, d 2 is a table lo o kup that takes a po sition in H a nd returns the distance to the iden tity element ( e ) using mov es in S . (Koc iem ba ac- tually uses a s ma ller, faster table tha t gives a b ound on this v alue; see [2 ] for details.) The for lo op is implemen ted b y a depth-first recursive routine that Page 4 Algorithm 1 Ko ciemba’s Algorithm. 1: d ← 0 2: b ← ∞ 3: while d < b do 4: for s ∈ S d , r ( ps ) = e do 5: if d + d 2 ( ps ) < b then 6: Solve phase 2; rep ort new b etter solution 7: b = d + d 2 ( ps ) 8: end if 9: end for 10: d ← d + 1 11: end while maint ains ps incrementally and has a num ber of fur- ther refinemen ts, such as not permitting s to end in a mov e in A . The phase tw o s olution pro cess is o mit- ted b oth b ecause it is s tr aightforw ard and b ecause it takes muc h less time than en umerating phase one solutions. This algo rithm is extremely effective. Some reaso ns are: 1. Pha se one solutions a re found very fas t, and mostly a ccess the p o rtions o f the phase 1 lo okup table near the s o lved p osition; this lo cality en- hances the utilit y o f caches significantly . 2. When sea rching for a phase 2 solution, almost alwa ys the very first lo okup shows that the dis- tance to the so lved p osition would ma ke the total solution lo nger than the be s t found so far; th us, almost all phase 1 solutions are rejected with a single lo okup in the phas e 2 table. 3. Ko c iemba has found that in practice the algo - rithm runs considera bly faster if he do es not con- sider phase 1 so lutions that contain a strict prefix that is a lso a phase 1 solution. This is motiv a ted b y the fact that we had a lready explored that prefix earlier (since we consider phase 1 so lutions b y incr easing length). 4. The last move at the end o f phas e 1 is a lwa ys a quarter tur n of F, B, R, o r L; the inv erse mov e is also a solution of phase 1 , so candidate solutions are always found in pairs a t the leav es of the phase 1 se arch tree. 5. There are a num b er o f optimizations that can be per formed for the phase 1 search when the distance to H is small, s uch as storing sp ecif- ically which moves decrea se the distance from that p oint. Ko ciemba’s algor ithm can b e run as describ ed ab ov e, or it can b e run in triple-a xis mo de. Note how the algorithm treats the u and d faces differently than the other four. Instead o f just explor ing a sing le given po sition p , in triple-axis mo de we explor e three rotated p ositions, one with the cub e rotated such that the r and l faces corr esp ond to u and d, o ne s uch that the b and f faces corr e spo nd to u and d, and the or ig- inal unrotated pos ition. W e try ea ch r otation fo r a given pha se 1 depth befor e moving on to the next phase 1 depth. Our tests sho w that this finds smaller po sitions mu ch fas ter than the standa rd sing le-axis mo de; when trying to find solutions of length 2 0 or less, this works approximately s ix times faster o n a v- erage than single-axis sear ch. W e hav e taken this idea one s tep further; we also consider the in verse p osition in three orientations for a new six-axis mo de. W e find this gives on average a further factor o f tw o sp eed increa se when trying to find p ositions o f tw ent y mov es or less. 6 Our Set Solv er Reid show ed a b ound of 30 b y proving it takes no more than 12 mo ves to bring an arbitrary cub e p o - sition to the H set (b y solving the restick ered cub e), and then showing that every cub e p osition in H ca n be s olved in 18 mov es. (He then reduced tha t to 29 with a clever insight we omit for brevity[6].) Our pro of o f 25 is similar, but instead of using just the H set, we use a union of thousands of sets all related to H . Consider how Ko ciemba’s solver solves an ar bitrary po sition to find a near-optimal solution. It first brings the po sition into H , using so me sequence of mov es, and then ca lculates within H how close to solved it is. It then finds another wa y to bring the p osition in to H , a nd ch ecks how clos e it is to solved at that po int . It do es this dozens, or hundreds, o r thousands, millions, or even billions o f times, each time chec king for a sho rter solution. W e turn this technique inside out. Instead of us- ing a big table c ontaining, for each po sition within H , how close it is to solved, instead w e use a table that indicates whether we’ve gotten to that partic- ular p osition in H a lr eady . W e then en umerate a ll sequences that take that initial pos ition into H , for longer and longer p ositions, un til that table is com- pletely marked; that every p osition has b een seen. At this p oint, the length of the longest s equence we con- sidered is the maxim um distance from solved for an ent ire large set of p ositions; sp ecifically , all those p o- sitions that, when phase-o ne r elab eled, give the sa me Page 5 lab eling as the initial p os itio n we started with. With this technique, we are essentially so lving 20 billion cube p o s itions, ra ther than one; if we were to write out each sequence every time w e set a new bit in the lar ge table, we would even tually write out an optimal sequence for every pos ition in that set. The main input to our set solver is a sequence a ∈ S ∗ , which takes the solved cub e in to some p os ition; the set that will b e solved is H a . Another input is the maximum depth m to run the phase one s e a rch; we have found the v alue m = 16 is usually s ufficien t to prov e an upper bo und for the distance of the set to b e 2 0 . T o find the ex act distance, m should be set to ∞ . Our algorithm is given as Algorithm 2 . In line Algorithm 2 Set Solver 1: f ← ∅ 2: d ← 0 3: lo op 4: f = f ∪ Af { —pr ep ass } 5: if f = H a then 6: return d 7: end if 8: if d ≤ m then 9: for s ∈ S d , r ( as ) = e do { –se ar ch } 10: f ← f ∪ s − 1 11: end for 12: end if 13: if f = H a then 14: return d 15: end if 16: d ← d + 1 17: end loo p 4, we use left m ultiplication of a set b y a mo ve; this is unconv entional but still quite fast. In line 9, s is the so lution to the p osition r e a ched by s − 1 . Unlike Ko ciemba’s search, we do per mit o ur phase 1 se arch to en ter and then leav e the H group; w e do this in order to compute the pr ecise s et bo und (should we wan t to). W e hav e not yet explored the p erfo rmance impact of this on our running time. The s et f is represented by a bitmap, one bit p er po sition. F or the prepass (line 4), we need to hav e bo th a source and destination set, s o w e need to hav e t wo of these bitmaps in memor y at o nce. Our mem- ory requirements are co mpletely dominated by these bitmaps, requiring a tota l o f 4 .7GB of memory . F or po sitions in R that hav e sy mmetry , we ta ke adv a n- tage o f that symmetry to run the positions on older machines without that muc h memory . The indexing of f is done by splitting the cub e po sition int o indep endent co or dinates, representing the p er m utation of the corners, the p ermut ation of the up/down edges, a nd finally the p ermutation of the middle edg es. The time sp ent in the co de is split betw een the prepass and the search phases. The prepass is a sim- ple scan over the ent ire f set, multiplying b y the ten mov es in A ; this ca n b e done efficiently by handling the co o rdinates from most significant to lea s t signif- icant in a r ecursive algor ithm so that the inner lo op only need deal with the per mutation of the middle edges, and the more exp ensive cor ner co ordinate c om- putation is per formed early in the rec ur sion and thus substantially fewer times. The time in the search phase (lines 9–11) is v ery small for low d , b ecause there are few sequences s that satisfy the conditions, but as d grows, so do es the time for the sea rch phase, exp onentially . Typically a search at level d + 1 will require ten times a s muc h time as a search at lev el d . By limiting m to 16 in the t ypical case, we limit the total time in the search phase, and the whole progra m runs fast. F or v a lues of m of 17 or higher, the s e a rch pha se will dominate the total runtime. Our current implementation o f this se t solver has a ma jor restriction; at the moment it only solves those sets for which the middle four edges a re placed in the middle. This restrictio n simplifies some of the mo ve calculations, but it is no t essential to our basic ideas. In the future we plan to lift this r estriction. 7 Impro ving the Bound Some sets we solve hav e relatively few p ositions in the furthest distance. Since for lower v a lues of m our set so lver o nly gives us an uppe r b ound on the set distance, in ma ny cases the true distance o f all these po sitions is less than the ca lculated upp er bound. By solving these ex plicitly using a sing le-cub e solver, and proving they do not r equire as many mov es a s o ur set solver found, we ca n frequently reduce our bo und on the distance for the set b y 1 . T o facilitate this, if the count of unsolved p ositions in one of the se ts falls below 6 5,536 at the top o f the lo op, we print each of these p ositions to a log file. T o solve these po sitions, we first us e our six-a x is im- plemen tation of Ko ciemba’s solution algorithm. Since the solution distance we seek is a lmost always 19 or 20, this algor ithm finds s o lutions very quickly , usu- ally in a fractio n of a s e cond. F or those p o s itions that resist K o ciemba’s solver, w e solve them us ing our optimal s o lver. Page 6 8 The Set Graph The set R of rela be led po sitions of G has ab out tw o billion e lements. Consider a po s ition a ∈ R ; we can define the set of a to be all elemen ts g ∈ G such that r ( g ) = a . Let us pick a single one of the elements i in the set of a ; the entire set can b e r epresented by H i . Each set ha s precis e ly the same num b er of elements, ab out 20 billion; ev ery pair of sets is either identical or disjoint; a nd the union of a ll of the sets is G , the full cube s pace. (This can be s hown with elementary group theory b ecaus e H is a subgroup of G and each set H i is a cos e t.) These se ts are all related by the mov es in S . Con- sider a cube position a and its set H a . The set H ab for b ∈ S is adjacent to the set H a . W e can consider R as a graph, wher e the vertices a re the sets r epresented by the p ositions o f R , a nd the edges are mov es in S . Clearly for any given p osition | d ( ab ) − d ( a ) | ≤ 1, and therefor e the same is true fo r sets as a whole: | d ( H ab ) − d ( H a ) | ≤ 1. If we ha ve shown that d ( H a ) ≤ c for so me v alue of c , we hav e also sho wn that d ( H as ) ≤ c + | s | where s ∈ S ∗ and | s | is the length of s . This allows us to find an upper bo und for one set, and use it to infer constraints on upper b ounds o f neighboring sets in the g raph of R . The relab eled puzzle shows 16-way symmetry , so there are rea lly o nly a b out 139 million rela b e le d p o- sitions when r educed by this symmetry . This reduced graph easily fits into memory , and op erations on this graph ca n be per fo r med rea sonably q uic kly . F or eac h vertex, we maintain a v alue which is the least upper bo und w e hav e proved to date. These v alues are ini- tialized to 30, since we know every p osition and thus every set has a distance of no more than that. As w e solve new s ets, we up date the v alue for the vertex as- so ciated with that set, and update adjacent vertices recursively with the new upper b ound implied by this v alue. 9 Eliminati ng Unneeded Sets Just as the triple-a xis search improves the pe r for- mance of Ko ciemba’s algorithm, we can use remap- pings to decrea se the amount o f work needed to prove a new bo und on the diameter. The R-relab eled cub e’s space can be defined by three co ordinates: the placement o f the four middle edges, the orientation o f the eigh t corners, and the orientation of the tw elve edges. Note that the mid- dle edges are those b etw een the up and down faces. If you reo rient the cub e so the R and L faces ar e up and down, then the four edges that were b et ween R and L are now the middle edges. Similarly , if you r eorient the cub e so the F and B faces are up a nd down, the the four edges that were b etw een F and B are now middle edges. Thus, the same or iginal cube po s ition has three relab els dep ending on orientation, and the middle edge p os itioning for these three o rientations cov er all tw elve edg es of the cube. Each co rner cubie in the g raph is adjacent to thr e e edges. Therefore, there are eight corners a djacent to an o dd n umber of edges. Consider any subset a of edges, and count the n umber of corner s adjacent to an o dd num b er o f edges in that subset; c a ll that f ( a ). F or any t wo subsets a and b , f ( a + b ) ≤ f ( a ) + f ( b ). If we par tition the tw elve edges into three subsets a , b , and c , and we kno w that f ( a ) + f ( b ) + f ( c ) = 8, then at least one of f ( a ), f ( b ), or f ( c ) must be thr e e or mor e . Therefore, every cub e p os ition has some orienta- tion where the middle edges in that orientation hav e an o dd corner count ( f ) o f thr e e or mor e. If we find an orientation-independent prop erty that applies to all of these subsets, we can ex tend that prop erty to the full set of cube p ositions, s ince there is some o ri- ent ation of every cub e pos itio n that lies within one of these subsets. This idea is easily g eneralized. The relab eled cub e po sition information can b e descr ibe d by three inde- pendent co ordinates: the middle edge po sitions, the edge orientations, and the co rner orientations. F or each of co or dinates, the full set of p oss ible combina- tion three -tuples ca n b e explicitly e numerated. Giv en these three-tuples, a cov ering set based on any par- ticular weigh ting can b e chosen. Using the middle edge p osition or the corner orient ation, it is not dif- ficult to eliminate a third of the sets; with the edge orientation, it is not difficult to eliminate half of the sets. F o r the r esults in this pap er, we hav e eliminated sets to solve bas e d on the edge p ositioning, b eca use the restrictions o f our se t solver make this the mos t adv antageous co ordina te to use. W e hav e eliminated 94 p ossible middle edge p ositions out of the 4 95 pos - sible, including ones that are the furthest from the middle-edges-in-middle restriction of our set solver. This eliminated 25.7 million of the 138 .6 million sets, esp ecially those furthest from the ones that our set solver co uld solve. 10 Cho osing S ets to Solv e This work grew out of a sear ch for distance 21 po sitions[8] that inv olved solving a num b er of these sets exactly . W e th us started this work with a few thousand cosets alre a dy solved; we used those as our Page 7 base set. At every point during this exploration we maint ained the symmetry-reduced gr a ph R on disk annotated with the bes t upper b ound we had prov en for each cor resp onding set. T o s e le c t a new set to solve, we used a simple greedy strateg y . W e chose a vertex that, when we pushed its b ound down to 20, and prop ogated its implications ov er the g r aph R , it would reduce the maximum num ber of vertices from ab ov e 2 5 to 25 or less; we ca ll this v alue the ‘impact’ of the v ertex. W e annotated e a ch no de with this v alue as well. The candidate set was small, since restrictions in our set solver mean that it can only solve approximately 288,0 0 0 o f the 139 million sets. Once we had selected a vertex, we a dded it to the list of s ets to solve, upda ted the re le v ant vertices on the in- memory copy of the gra ph (not the p ersis ten t one on disk ), and r ep eated this pr o cess to select an- other vertex. Si nce the potential impact of so lving a pa rticular vertex only decreased as other vertices were solved, we skipp ed vertices that had a prior im- pact scor e les s than the curr ent b est; this allowed subsequent vertices to b e selected re la tively quickly . W e typically g enerated lis ts of a few h undred sets to so lve in this manner. Since some of the s e ts actu- ally ca me in with a b ound o f 19 or even 18 , and this changed the gr aph in wa ys differen tly than o ur ab ov e algorithm assumed, we genera ted a brand new list of vertices to solve every few days based on the upda ted R gr aph. 11 Correctness F or computer sear ches such as this one, it is imp era- tiv e that the progra ms b e correct. In order to ensure this, we hav e taken a num b er of meas ures: 1. W e developed an independent, simple set solver that uses the simplest po ssible co de with a sim- ple hashtable structure to stor e the found po si- tions. W e compared the results of our fast set solver a gainst this simpler, s low er pr ogram, to the search depth that the simpler pr o gram was able to handle. W e also co mpared the full se t of po sitions found b etw een the tw o prog rams to the depth p ossible. 2. All set solutions were so lved only on server-class machines containing erro r -chec ked-and-corrected memory . 3. All s eparately so lved cube p ositions were taken as sequences, and a separa te progr am was run to aggreg ate these p ositions in to a simple database of so lved p ositions. W here upper bo unds were reduced by calculating solutions for small sets of po sitions, these sequences were queried and ver- ified that they did, indeed, yield the appro pr iate po sition. 4. Every optimization, including symmetry reduc- tions of v arious kinds, sea rch r estrictions, parallel m ulticore op eration, and so on, w ere sw itchable on and off, and the results of the prog ram v ali- dated. 5. As a sa nit y chec k, from the 2 1 found distance- 18 sets, a random 3,0 00,00 0 cub e p ositions were selected and for each of these, using the six-axis Ko ciemba solver, a solution of length 18 or b etter was found. 12 Results Solving sets with sy mmetry can be done with ma- chi nes that do not have muc h memory . Initially our largest machine had 3.5GB of RAM, not enough to solve sets la cking symmetry . So w e started with the sy mmetrica l sets. The s ymmetrical sets are a lso faster to s olve, but the results from the symmetrical sets were insufficient to pr ov e a bo und of 25 . W e then purchased a ma chin e with 8GB of memory and set it to solving sets lacking symmetry . W e selected sets to solve based on how many neighbor s would b e re- duced to b elow 25 b y solving that set, a ssuming an upper bound of 20 . After solv ing approximately tw o thousand additional sets, we w ere able to bring the upper b ound for each vertex in the set gra ph b elow 26, proving that every p os ition of Rubik’s cub e can be solved in 25 o r fewer mo ves. W e hav e to da te found 21 sets that have a distance of 18 or less , 948 that have a distance of 19 or les s, a nd 7,990 that hav e a distance of 20 or less. Because we initially fo cused on symmetrica l sets (due to memory constraints), man y of these s ets are neig hbors, a nd some are redundant (for instance, a set with a low er bo und of 1 9 , that is adjacent to a s et with a lower bo und of 1 8, is redundant b ecause the latter implies the former.) The 21 sets we have found that hav e a distance o f 18 a re listed in T able 2 . These, and all other sets, ar e given by a represe ntative elemen t; ǫ means the re pr esentativ e element is the empt y se- quence so that set is just H . An y single set that w e’ve shown to be 18 , with the exception of the ǫ s et immediately pr ov es a b ound of 29 on G b ecause every no de in the graph of R is within 11 edges of some o rientation of each of these sets. Page 8 d sequence 18 ǫ 18 R ′ B2UB2U ′ R 18 R ′ DL2D ′ R 18 R ′ U ′ R2F2R ′ F2UR ′ 18 B ′ U ′ R2UR2B ′ 18 F ′ R2UR2U ′ F ′ R2U ′ 18 F ′ DFR2U ′ FU2F ′ 18 F ′ D ′ BR2BDF 18 B ′ L2R2F ′ D2U2F ′ U 18 B ′ U ′ F2UB ′ U ′ 18 F ′ D ′ BR2BDF ′ 18 B ′ D ′ L2DL2B ′ R2 18 R ′ F2U2RF2R2U2R ′ 18 R ′ DL2D ′ R U ′ 18 B ′ UF2U2F2UB ′ 18 L ′ D ′ U ′ L ′ DUL ′ U ′ 18 F ′ UFUF ′ U2F ′ 18 F ′ DUF ′ D ′ U ′ F ′ U ′ 18 B ′ DUB ′ D ′ U ′ B ′ 18 F ′ D ′ F ′ R2B ′ D ′ B ′ 18 B ′ D2R2U2L2F T able 2: All known sets (by representativ e) that hav e a distance of exactly 1 8. d sequence 20 R ′ B2U ′ L ′ F ′ D2R2D ′ LB ′ U ′ 20 R ′ D2B ′ L ′ ULF ′ R ′ F2D ′ B 19 F ′ L ′ DF ′ U ′ R ′ B2R ′ 19 L ′ BF ′ DU ′ B ′ RF2L ′ F ′ U ′ T able 3: F o ur sets, with the given upper b o unds o n distances, that can b e added to the set of 18’s to prove a distance of 27 fo r the s e t G . Proving these sets to b e 18 to o k four or five hour s each; in so me cases, w e r an our solver with m = 17, and in other ca ses we simply solved the remaining po sitions at the top level. No single set we hav e solved by itself sho ws a bo und of 28 for the diameter of G , but many pair s of the o nes listed ab ov e do. O ne example such pair is B ′ UF2U2F2UB ′ and B ′ U ′ R2UR2B ′ . That is, just solving these tw o sets pr ov es a b ound of 28, b ecause every set in the graph of R is within 10 moves o f some orientation of one of these tw o sets. T o prov e a b ound of 27 for G , we include all 21 of the sets we list a b ove, plus an additional four sets listed in T able 3. These 25 sets ar e sufficient to br ing every necessar y no de of R down to a b o und of 2 7. This list w as determined with a greedy search. W e started with our set of 21 distance-18 s ets, and pro- po gated their implications ov er the g raph of R . W e then iteratively chose the solved s et that had the greatest impact o n R (reduced the maximum num- ber of vertices fro m 28 or mo re to b elow 28, in this case), until all v ertices were b elow 28 . All subse quent set counts mentioned were genera ted by this sort o f po st-pass over our collec tio n of so lved sets. T o repro duce the re sult of Co op er man a nd Kunkle, all of the ab ov e sets plus an additiona l 1 27 s e t b ounds that we have found are needed, fo r a total o f 15 2 sets. Our new result requir es a total of 3,868 set bo unds (abo ut half of the total num b er we hav e solved). This includes 62 1 of the sets for which we’ve s hown a bo und of 19, and 3,2 26 of the s ets for which w e’ve shown a b ound of 20. It is difficult to say wha t the total exe c ution time has b een, b eca use most of the sets were run slowly , us- ing a n older, slow er version of the set solver, on older, slow er hardware. But given that the current version of the pro gram, on a mo dern Q66 00 CPU running at 1.6GHz, using a v alue of m = 16, a nd proving a set to a depth of 20, can b e done in 18 minut es o n a verage, and taking into acco unt the individual po sitions we solved to lower some of the set b ounds, we b elieve the total execution time would b e on the order of 1,500 CPU hour s to repr o duce our pro of o f 25. W e co nt inue to execute sets, and we a re ma king progres s tow ard proving a bound of 24 . In order to complete this pro o f without requiring an inordinate n umber of sets, we need to lift the restriction o n our set solver that it o nly solve sets that hav e the middle edges in place. Once this is done, we be lieve that with only a few more CPU mont hs, w e can show a new b ound of 24 o n the diameter of the cub e gr o up. 13 Ac kno wledgemen ts This work was grea tly help ed b y discussions with Sil- viu Radu; it was he who dir ected us to the subgroup (called H here) used by Ko ciemba. W e a re als o gr ate- ful to Herb ert K o ciemb a for b oth his or iginal 1992 al- gorithm (and its implemen tation in Cub e Explor er) and for some email discus sions. References [1] Ko cie mba, Herb ert. “Clos e to Go d’s Algo r ithm” Cubism F or F un 2 8 (April 199 2 ) pp. 10-1 3. [2] Ko cie mba, Herb ert. Cube Explo rer (Windows progra m). h ttp:// kocie mba.org/cube.htm Page 9 [3] Kunkle, D.; Co op erman, G. “ Twen ty-six Moves Suffice for Rubik’s Cub e.” Pr o c e e dings of the In- ternational Symp osium on Symb olic and Alg e- br aic Computation (ISSAC ’07) , ACM Press . [4] Korf, Richard E. “Finding Optimal Solutions to Rubik’s Cube Using Pattern Databases.” Pr o- c e e dings of the Workshop on Computer Games (W31) at IJCAI-97. [5] Radu, Silviu. “New Upper Bounds on Rubik’s cube.” http:/ /www. risc.uni-linz.ac.at/publications/download/risc 3122/u ppern ew3.p s [6] Reid, Michael. “ New upp er bo unds.” cube- lov ers e-mail, January 7 , 19 95. [7] Reid, Michael. “ Super flip requires 20 face turns.” cube- lov ers e-mail, January 18, 199 5 . [8] Rokicki, T omas. “In search of: 21f*s and 20f*s; a four month o dys s ey .” 7 May 20 06. http:/ /cube zzz.homelinux.org/drupal/?q=node/view/56 Page 10
Original Paper
Loading high-quality paper...
Comments & Academic Discussion
Loading comments...
Leave a Comment