# "Singmaster" to "Cubestring" conversion



## TheDuckCuber (Nov 15, 2022)

Background: Python coder (amateur at best) here, won't understand some of the coding jargon so please excuse me beforehand.

So I was trying to make a Rubik's cube application with python the other day, and I decided for the scrambler I'd use Kociemba's 2-phase solver for the scramble generator. But the program requires the cube state to be inputted with the colour of each sticker on the cube while I have the cube states saved in the Singmaster notation. i.e., the common notation used by the average cuber (RLUDFB etc.). Is there a way to convert the notation my cube states in a way that the program is not made significantly slower?

All answers welcome.


----------



## Mastermind2368 (Nov 15, 2022)

I'm a little confused on how exactly your program is intended to store the cube state. Is it a single list? A list of lists? A 54 character string? 

If it's something like that, you can create functions which are each defined as a different turn, and cycle the correct pieces for the corresponding rotation. If you wanted to rotate R, you would have to find the indexes of all the stickers in the R slice, and move each sticker to the next position. 

I made something like this at one point (no scrambler though, just a 2d virtual cube) and I ended up doing that approach. Then to call the Singmaster notation, I made a function which takes a string and calls the other functions based upon the input.


----------



## Bruce MacKenzie (Nov 15, 2022)

TheDuckCuber said:


> Background: Python coder (amateur at best) here, won't understand some of the coding jargon so please excuse me beforehand.
> 
> So I was trying to make a Rubik's cube application with python the other day, and I decided for the scrambler I'd use Kociemba's 2-phase solver for the scramble generator. But the program requires the cube state to be inputted with the colour of each sticker on the cube while I have the cube states saved in the Singmaster notation. i.e., the common notation used by the average cuber (RLUDFB etc.). Is there a way to convert the notation my cube states in a way that the program is not made significantly slower?
> 
> All answers welcome.



I'm not sure what you mean by Singmaster notation. Kociemba's Cube Explorer accepts input in the form of a permutation of the identity string;

"UF UR UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR"

This representation is composed of twenty groupings which name the twenty cubies which are rearranged by turns of the cube faces. The two letter groupings represent the edge cubies and the three letter groupings represent the corner cubies. The individual letters stand for the exposed facelets of the cubies using the Singmaster convention. UF stands for the cubie on the Up-Front edge of the solved cube. UFR stands for the cubie in the Up-Front-Right corner of the solved cube.

Arbitrary cube arrangements are encoded as a rearrangement of the identity representation. For example, a three way swap of the UF, UR and UB cubies would be shown as:

"UR UB UF UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR"

This string specifies that the UR cubie has been moved to UF cubicle, the UB cubie has been moved to the UR cubicle and the UF cubie has been moved to the UB cubicle. Cubie orientation is encoded as a rearrangement of the letters in the letter groupings. A cube position having the UF and UR cubies flipped would be encoded as:

@ "FU RU UB UL DF DR DB DL FR FL BR BL UFR URB UBL ULF DRF DFL DLB DBR"

Here the UF cubie is in the UF cubicle but with the Front facelet in the Up position. Corner cubie twist is encoded by rolling the three letter codes to the right or the left. If the UFR corner cubie is shown as FRU, the Front facelet has been rotated to the Up position and the cubie has a CW twist. If it is shown as RUF, the Right facelet has been rotated into the Up position and the cubie has a CCW twist. Note that swapping two letters of a corner cubie, ie FUR, represents the mirror image of the cubie and is not valid in a SCS representation.

Here's a screen shot of a cube state and its string representation:


----------



## TheDuckCuber (Nov 16, 2022)

Mastermind2368 said:


> I'm a little confused on how exactly your program is intended to store the cube state. Is it a single list? A list of lists? A 54 character string?
> 
> If it's something like that, you can create functions which are each defined as a different turn, and cycle the correct pieces for the corresponding rotation. If you wanted to rotate R, you would have to find the indexes of all the stickers in the R slice, and move each sticker to the next position.
> 
> I made something like this at one point (no scrambler though, just a 2d virtual cube) and I ended up doing that approach. Then to call the Singmaster notation, I made a function which takes a string and calls the other functions based upon the input.


hmm yeah I'll see that. the programs stores the cube state based on the set of moves taken to reach that state


----------



## Bruce MacKenzie (Nov 16, 2022)

Ok, so you need to convert a generator turn sequence into a string representation suitable for input into Kociemba's 2 phase solver.

1. Represent the face turns as S54 permutations of the facelet positions. Kociemba gives the order he lists the facelets in the enums.py file.

2. Convert the generator turn sequence into a S54 permutation by compositing the face turn permutations using permutation multiplication;

3. Apply the composit permutation to the identity string: "UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB"

Addendum

I sat down and wrote some code to convert my cube representation to an S54 representation using Kociemba's numbering and printed out the face turns. Hope you find this useful.
The S54 reps may be used to composit turn sequences and permute the facelet color string. The GAP permutation rep is in 1 based canonical cycle notation suitable for GAP.

R UUFUUFUUFRRRRRRRRRFFDFFDFFDDDBDDBDDBLLLLLLLLLUBBUBBUBB

S54 = { 0, 1,20, 3, 4,23, 6, 7,26,15,12, 9,16,13,10,17,14,11,18,19,29,21,22,32,24,25,35,27,28,51,30,31,48,33,34,45,36,37,38,39,40,41,42,43,44, 8,46,47, 5,49,50, 2,52,53}

GAP: (3,21,30,52)(6,24,33,49)(9,27,36,46)(10,16,18,12)(11,13,17,15)
`_____UUF
_____UUF
_____UUF
LLL FFD RRR UBB
LLL FFD RRR UBB
LLL FFD RRR UBB
_____DDB
_____DDB
_____DDB`

R' UUBUUBUUBRRRRRRRRRFFUFFUFFUDDFDDFDDFLLLLLLLLLDBBDBBDBB

S54 = { 0, 1,51, 3, 4,48, 6, 7,45,11,14,17,10,13,16, 9,12,15,18,19, 2,21,22, 5,24,25, 8,27,28,20,30,31,23,33,34,26,36,37,38,39,40,41,42,43,44,35,46,47,32,49,50,29,52,53}

GAP: (3,52,30,21)(6,49,33,24)(9,46,36,27)(10,12,18,16)(11,15,17,13)
`_____UUB
_____UUB
_____UUB
LLL FFU RRR DBB
LLL FFU RRR DBB
LLL FFU RRR DBB
_____DDF
_____DDF
_____DDF`

U UUUUUUUUUBBBRRRRRRRRRFFFFFFDDDDDDDDDFFFLLLLLLLLLBBBBBB

S54 = { 6, 3, 0, 7, 4, 1, 8, 5, 2,45,46,47,12,13,14,15,16,17, 9,10,11,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,18,19,20,39,40,41,42,43,44,36,37,38,48,49,50,51,52,53}

GAP: (1,7,9,3)(2,4,8,6)(10,46,37,19)(11,47,38,20)(12,48,39,21)
`_____UUU
_____UUU
_____UUU
FFF RRR BBB LLL
LLL FFF RRR BBB
LLL FFF RRR BBB
_____DDD
_____DDD`

U' UUUUUUUUUFFFRRRRRRLLLFFFFFFDDDDDDDDDBBBLLLLLLRRRBBBBBB

S54 = { 2, 5, 8, 1, 4, 7, 0, 3, 6,18,19,20,12,13,14,15,16,17,36,37,38,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,45,46,47,39,40,41,42,43,44, 9,10,11,48,49,50,51,52,53}

GAP: (1,3,9,7)(2,6,8,4)(10,19,37,46)(11,20,38,47)(12,21,39,48)
`_____UUU
_____UUU
_____UUU
BBB LLL FFF RRR
LLL FFF RRR BBB
LLL FFF RRR BBB
_____DDD
_____DDD
_____DDD`

F UUUUUULLLURRURRURRFFFFFFFFFRRRDDDDDDLLDLLDLLDBBBBBBBBB

S54 = { 0, 1, 2, 3, 4, 5,44,41,38, 6,10,11, 7,13,14, 8,16,17,24,21,18,25,22,19,26,23,20,15,12, 9,30,31,32,33,34,35,36,37,27,39,40,28,42,43,29,45,46,47,48,49,50,51,52,53}

GAP: (7,45,30,10)(8,42,29,13)(9,39,28,16)(19,25,27,21)(20,22,26,24)
`_____UUU
_____UUU
_____LLL
LLD FFF URR BBB
LLD FFF URR BBB
LLD FFF URR BBB
_____RRR
_____DDD
_____DDD`

F' UUUUUURRRDRRDRRDRRFFFFFFFFFLLLDDDDDDLLULLULLUBBBBBBBBB

S54 = { 0, 1, 2, 3, 4, 5, 9,12,15,29,10,11,28,13,14,27,16,17,20,23,26,19,22,25,18,21,24,38,41,44,30,31,32,33,34,35,36,37, 8,39,40, 7,42,43, 6,45,46,47,48,49,50,51,52,53}

GAP: (7,10,30,45)(8,13,29,42)(9,16,28,39)(19,21,27,25)(20,24,26,22)
`_____UUU
_____UUU
_____RRR
LLU FFF DRR BBB
LLU FFF DRR BBB
LLU FFF DRR BBB
_____LLL
_____DDD
_____DDD`

L BUUBUUBUURRRRRRRRRUFFUFFUFFFDDFDDFDDLLLLLLLLLBBDBBDBBD

S54 = {53, 1, 2,50, 4, 5,47, 7, 8, 9,10,11,12,13,14,15,16,17, 0,19,20, 3,22,23, 6,25,26,18,28,29,21,31,32,24,34,35,42,39,36,43,40,37,44,41,38,45,46,33,48,49,30,51,52,27}

GAP: (1,54,28,19)(4,51,31,22)(7,48,34,25)(37,43,45,39)(38,40,44,42)
`_____BUU
_____BUU
_____BUU
LLL UFF RRR BBD
LLL UFF RRR BBD
LLL UFF RRR BBD
_____FDD
_____FDD
_____FDD`

L' FUUFUUFUURRRRRRRRRDFFDFFDFFBDDBDDBDDLLLLLLLLLBBUBBUBBU

S54 = {18, 1, 2,21, 4, 5,24, 7, 8, 9,10,11,12,13,14,15,16,17,27,19,20,30,22,23,33,25,26,53,28,29,50,31,32,47,34,35,38,41,44,37,40,43,36,39,42,45,46, 6,48,49, 3,51,52, 0}

GAP: (1,19,28,54)(4,22,31,51)(7,25,34,48)(37,39,45,43)(38,42,44,40)
`_____FUU
_____FUU
_____FUU
LLL DFF RRR BBU
LLL DFF RRR BBU
LLL DFF RRR BBU
_____BDD
_____BDD
_____BDD`

D UUUUUUUUURRRRRRFFFFFFFFFLLLDDDDDDDDDLLLLLLBBBBBBBBBRRR

S54 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,24,25,26,18,19,20,21,22,23,42,43,44,33,30,27,34,31,28,35,32,29,36,37,38,39,40,41,51,52,53,45,46,47,48,49,50,15,16,17}

GAP: (16,25,43,52)(17,26,44,53)(18,27,45,54)(28,34,36,30)(29,31,35,33)
`_____UUU
_____UUU
_____UUU
LLL FFF RRR BBB
LLL FFF RRR BBB
BBB LLL FFF RRR
_____DDD
_____DDD
_____DDD`

D' UUUUUUUUURRRRRRBBBFFFFFFRRRDDDDDDDDDLLLLLLFFFBBBBBBLLL

S54 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,51,52,53,18,19,20,21,22,23,15,16,17,29,32,35,28,31,34,27,30,33,36,37,38,39,40,41,24,25,26,45,46,47,48,49,50,42,43,44}

GAP: (16,52,43,25)(17,53,44,26)(18,54,45,27)(28,30,36,34)(29,33,35,31)
`_____UUU
_____UUU
_____UUU
LLL FFF RRR BBB
LLL FFF RRR BBB
FFF RRR BBB LLL
_____DDD
_____DDD
_____DDD`

B RRRUUUUUURRDRRDRRDFFFFFFFFFDDDDDDLLLULLULLULLBBBBBBBBB

S54 = {11,14,17, 3, 4, 5, 6, 7, 8, 9,10,35,12,13,34,15,16,33,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,36,39,42, 2,37,38, 1,40,41, 0,43,44,51,48,45,52,49,46,53,50,47}

GAP: (1,12,36,43)(2,15,35,40)(3,18,34,37)(46,52,54,48)(47,49,53,51)
`_____RRR
_____UUU
_____UUU
ULL FFF RRD BBB
ULL FFF RRD BBB
ULL FFF RRD BBB
_____DDD
_____DDD
_____LLL`

B' LLLUUUUUURRURRURRUFFFFFFFFFDDDDDDRRRDLLDLLDLLBBBBBBBBB

S54 = {42,39,36, 3, 4, 5, 6, 7, 8, 9,10, 0,12,13, 1,15,16, 2,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,17,14,11,33,37,38,34,40,41,35,43,44,47,50,53,46,49,52,45,48,51}

GAP: (1,43,36,12)(2,40,35,15)(3,37,34,18)(46,48,54,52)(47,51,53,49)
`_____LLL
_____UUU
_____UUU
DLL FFF RRU BBB
DLL FFF RRU BBB
DLL FFF RRU BBB
_____DDD
_____DDD
_____RRR`

R2 UUDUUDUUDRRRRRRRRRFFBFFBFFBDDUDDUDDULLLLLLLLLFBBFBBFBB

S54 = { 0, 1,29, 3, 4,32, 6, 7,35,17,16,15,14,13,12,11,10, 9,18,19,51,21,22,48,24,25,45,27,28, 2,30,31, 5,33,34, 8,36,37,38,39,40,41,42,43,44,26,46,47,23,49,50,20,52,53}

GAP: (3,30)(6,33)(9,36)(10,18)(11,17)(12,16)(13,15)(21,52)(24,49)(27,46)
`_____UUD
_____UUD
_____UUD
LLL FFB RRR FBB
LLL FFB RRR FBB
LLL FFB RRR FBB
_____DDU
_____DDU
_____DDU`

U2 UUUUUUUUULLLRRRRRRBBBFFFFFFDDDDDDDDDRRRLLLLLLFFFBBBBBB

S54 = { 8, 7, 6, 5, 4, 3, 2, 1, 0,36,37,38,12,13,14,15,16,17,45,46,47,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35, 9,10,11,39,40,41,42,43,44,18,19,20,48,49,50,51,52,53}

GAP: (1,9)(2,8)(3,7)(4,6)(10,37)(11,38)(12,39)(19,46)(20,47)(21,48)
`_____UUU
_____UUU
_____UUU
RRR BBB LLL FFF
LLL FFF RRR BBB
LLL FFF RRR BBB
_____DDD
_____DDD
_____DDD`

F2 UUUUUUDDDLRRLRRLRRFFFFFFFFFUUUDDDDDDLLRLLRLLRBBBBBBBBB

S54 = { 0, 1, 2, 3, 4, 5,29,28,27,44,10,11,41,13,14,38,16,17,26,25,24,23,22,21,20,19,18, 8, 7, 6,30,31,32,33,34,35,36,37,15,39,40,12,42,43, 9,45,46,47,48,49,50,51,52,53}

GAP: (7,30)(8,29)(9,28)(10,45)(13,42)(16,39)(19,27)(20,26)(21,25)(22,24)
`_____UUU
_____UUU
_____DDD
LLR FFF LRR BBB
LLR FFF LRR BBB
LLR FFF LRR BBB
_____UUU
_____DDD
_____DDD`

L2 DUUDUUDUURRRRRRRRRBFFBFFBFFUDDUDDUDDLLLLLLLLLBBFBBFBBF

S54 = {27, 1, 2,30, 4, 5,33, 7, 8, 9,10,11,12,13,14,15,16,17,53,19,20,50,22,23,47,25,26, 0,28,29, 3,31,32, 6,34,35,44,43,42,41,40,39,38,37,36,45,46,24,48,49,21,51,52,18}

GAP: (1,28)(4,31)(7,34)(19,54)(22,51)(25,48)(37,45)(38,44)(39,43)(40,42)
`_____DUU
_____DUU
_____DUU
LLL BFF RRR BBF
LLL BFF RRR BBF
LLL BFF RRR BBF
_____UDD
_____UDD
_____UDD`

D2 UUUUUUUUURRRRRRLLLFFFFFFBBBDDDDDDDDDLLLLLLRRRBBBBBBFFF

S54 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,42,43,44,18,19,20,21,22,23,51,52,53,35,34,33,32,31,30,29,28,27,36,37,38,39,40,41,15,16,17,45,46,47,48,49,50,24,25,26}

GAP: (16,43)(17,44)(18,45)(25,52)(26,53)(27,54)(28,36)(29,35)(30,34)(31,33)
`_____UUU
_____UUU
_____UUU
LLL FFF RRR BBB
LLL FFF RRR BBB
RRR BBB LLL FFF
_____DDD
_____DDD
_____DDD`

B2 DDDUUUUUURRLRRLRRLFFFFFFFFFDDDDDDUUURLLRLLRLLBBBBBBBBB

S54 = {35,34,33, 3, 4, 5, 6, 7, 8, 9,10,42,12,13,39,15,16,36,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, 2, 1, 0,17,37,38,14,40,41,11,43,44,53,52,51,50,49,48,47,46,45}

GAP: (1,36)(2,35)(3,34)(12,43)(15,40)(18,37)(46,54)(47,53)(48,52)(49,51)
`_____DDD
_____UUU
_____UUU
RLL FFF RRL BBB
RLL FFF RRL BBB
RLL FFF RRL BBB
_____DDD
_____DDD
_____UUU`


----------

