Mathematica, 413413 401 bytes
Evaluate[f/@Characters@"RFLBUD"]=LetterNumber@"ABFEJNRMDAEHIMQPCDHGLPTOBCGFKOSNADCBILKJEFGHQRST"~ArrayReshape~{6,2,4};
r[c_,l_]:=(b=Permute[c,Cycles@f@l];MapThread[(b[[#,2]]=Mod[b[[#,2]]+#3~Count~l2]]+{"F","B","L","R"}~Count~l{-1,1,-1,1},#2])&,{f@l,{3,2},Characters@{"FBLR","RLUD"}}];b);
p@s_:=Length[c={#,0}&~Array~20;NestWhileList[Fold[r,#,Join@@StringCases[s,x_~~t:""|"'":>Table[x,3-2Boole[t==""]]]]&,c,(Length@{##}<2||c!=Last@{##})&,All]]-1
In such notation, a 90 degree turn can be described by 8 movements of cubies. For example, R
is equivalent todescribed by
Since each cubie has a unique starting position, each position has a unique starting cubie. That is to say, rule UFR->UBR
is just 1->2
(means that R
takes the cubie on the starting position of cubie 1
to the starting position of cubie 2
). Thus, R
can be simplified further to a cycle
to be continued... To fully solve a Rubik's Cube, we also need to align the cubies to their corresponding starting orientations. The faces of a cube is painted in different colors, the scheme that I often use when solving cubes is
face color
U yellow
D white
F red
B orange
R green
L blue
When we analyzing the orientations of corners, colors other than yellow or white are ignored, and yellow and white are considered as the same color.
Suppose cubie 1
is on its starting position UFR
, the yellow facet may be aligned to three different faces. We use an integer to represent these cases,
0 yellow on U (correct)
1 yellow on R (120 degree clockwise)
2 yellow on F (120 degree counterclockwise)
Suppose cubie 1
is on DFL
, its three possible orientations are
0 yellow on D (correct)
1 yellow on L (120 degree clockwise)
2 yellow on F (120 degree counterclockwise)
When we analyzing the orientations of edges, red and orange are ignored, and yellow and white are ignored only if the edge has a green or blue facet.
Suppose cubie 10
is on its starting position UR
, the green facet may be aligned to two different faces. Its two possible orientations are
0 green on R (correct)
1 green on U (180 degree)
Suppose cubie 10
is on DF
, its two possible orientations are
0 green on D (correct)
1 green on F (180 degree)
An array is used to store the state of a cube. The starting state of a cube is
{{1,0},{2,0},{3,0},{4,0},{5,0},{6,0},{7,0},{8,0},{9,0},{10,0},{11,0},{12,0},{13,0},{14,0},{15,0},{16,0},{17,0},{18,0},{19,0},{20,0}}
which means that every cubies are on their starting position with correct orientation.
After R
, the state of the cube becomes
{{5,2},{1,1},{3,0},{4,0},{6,1},{2,2},{7,0},{8,0},{9,0},{13,1},{11,0},{12,0},{18,1},{10,1},{15,0},{16,0},{17,0},{14,1},{19,0},{20,0}}
which means that cubie 5
is now on position 1
(UFR
) with orientation 2
, cubie 1
is now on position 2
(UBR
) with orientation 1
, cubie 3
is now still on position 3
(UBL
) with orientation 0
, and so on.