# 关于魔方状态置换的快速解法

iniorder = {R, R, R, R, G, G, G, G, B, B, B, B, b, b, b, b, g, g, g, g, r, r, r, r};
endorder = {R, R, R, R, G, G, b, G, B, B, r, B, b, g, r, b, g, g, g, b, r, G, B, r};

smallcubeorder={{1,5,9},{2,12,17},{3,16,18},{4,6,13},{7,14,24},{8,10,21},{11,20,22},{15,19,23}};
inigroup={smallcubeorder,Part[iniorder,smallcubeorder[[#]]]&/@Range[Length[smallcubeorder]]};
endgroup={smallcubeorder,Part[endorder,smallcubeorder[[#]]]&/@Range[Length[smallcubeorder]]};


{{{1,5,9},{2,12,17},{3,16,18},{4,6,13},{7,14,24},{8,10,21},{11,20,22},{15,19,23}},{{R,G,B},{R,B,g},{R,b,g},{R,G,b},{G,b,r},{G,B,r},{B,g,r},{b,g,r}}}

{{{1,5,9},{2,12,17},{3,16,18},{4,6,13},{7,14,24},{8,10,21},{11,20,22},{15,19,23}},{{R,G,B},{R,B,g},{R,b,g},{R,G,b},{b,g,r},{G,B,r},{r,b,G},{r,g,B}}}


sortedinigroup=Transpose[SortBy[Transpose[inigroup[[All,#]]],Last]]&/@Range[Length[smallcubeorder]];
sortedendgroup=Transpose[SortBy[Transpose[endgroup[[All,#]]],Last]]&/@Range[Length[smallcubeorder]];


{{{9,5,1},{B,G,R}},{{12,17,2},{B,g,R}},{{16,18,3},{b,g,R}},{{13,6,4},{b,G,R}},{{7,14,24},{b,g,r}},{{10,8,21},{B,G,r}},{{20,22,11},{b,G,r}},{{23,19,15},{B,g,r}}}


sortedendorder =
sortedendgroup[[Position[sortedendgroup[[All, 2]],
sortedinigroup[[#, 2]]] // Flatten, 1]] & /@
Range[Length[smallcubeorder]] // Flatten


sortediniorder=sortedinigroup[[All,1]]//Flatten;
transdata=FindPermutation[SortBy[Transpose[{sortediniorder,sortedendorder}],First]//Transpose//Last,Range[24]]


Cycles[{{7, 22, 15}, {11, 23, 24}, {14, 20, 19}}]


iniorder={R,R,R,R,G,G,G,G,B,B,B,B,b,b,b,b,g,g,g,g,r,r,r,r};
endorder={R,R,R,R,G,G,b,G,B,B,r,B,b,g,r,b,g,g,g,b,r,G,B,r};
smallcubeorder={{1,5,9},{2,12,17},{3,16,18},{4,6,13},{7,14,24},{8,10,21},{11,20,22},{15,19,23}};
inigroup={smallcubeorder,Part[iniorder,smallcubeorder[[#]]]&/@Range[Length[smallcubeorder]]};
endgroup={smallcubeorder,Part[endorder,smallcubeorder[[#]]]&/@Range[Length[smallcubeorder]]};
sortedinigroup=Transpose[SortBy[Transpose[inigroup[[All,#]]],Last]]&/@Range[Length[smallcubeorder]];
sortedendgroup=Transpose[SortBy[Transpose[endgroup[[All,#]]],Last]]&/@Range[Length[smallcubeorder]];
sortedendorder=sortedendgroup[[Position[sortedendgroup[[All,2]],sortedinigroup[[#,2]]]//Flatten,1]]&/@Range[Length[smallcubeorder]]//Flatten;
sortediniorder=sortedinigroup[[All,1]]//Flatten;
transdata=FindPermutation[SortBy[Transpose[{sortediniorder,sortedendorder}],First]//Transpose//Last,Range[24]]


### 注记

transdata=FindPermutation[SortBy[Transpose[{sortediniorder,sortedendorder}],First]//Transpose//Last,Range[24]]


transdata=FindPermutation[SortBy[Transpose[{sortediniorder,sortedendorder}],First]//Transpose//Last]