21
2
Your task is to create a random sequence of moves, which can be used to scramble a Rubik's Cube. Such a scramble is made up of exactly 25 moves. Each move consist of of the letters UDRLFB optionally followed by one of the suffixes '2.
This notation is called the Singmaster notation. UDRLFB represents one of the 6 faces and the optional suffix '2 represents the turning angle. This information is in no way necessary to solve the task.
To assure, that the scrambles are of 'good quality', the following two rules have to apply:
Two consecutive moves must not have the same letter. This bans the consecutive moves
UU,DD,RR,LL,FFandBBand all their combinations using the optional suffixes likeU2UorU'U'.These move pairs are banned, because they can easily reduced to 1 or 0 moves.
U2Uhas the same effect asU',R'Rthe same effect as.Three consecutive moves must not be of the same letter group. The letter groups are
UD,RLandFB. This rule additionally bans the consecutive movesUDU,DUD,RLR,LRL,FBF,BFBand all their combinations using the optional suffixes likeU2DU,RL'RorB2FB'.The groups sort the faces by their move axis.
UandDare in the same group, because both turn around the same axis. Therefore anUmove doesn't influence the pieces of theDface, and aDmove doesn't influence pieces of theUface. Therefore the two moves can be exchanged,UDUhas the same effect asUUD, and this can be reduced toU2D.
Challenge
Write a script or a function, that generates one random scramble. There is no input. The script / function has to print the 25 moves without separation or separated by one space or return the correspondent string.
Your program has to be able to create every single scramble, which satisfies the rules above. Of course assuming, that the random number generator is true random, and not pseudo random.
This is code-golf. The shortest code (counted in bytes) wins.
Examples outputs:
Calling the script / function 3 times should print / return something like:
R'B2R2F2R2FB'R2DR2ULFB2RB'U2B'FL'BR'U'RB'
U'DBR'B2U'B'U'RUF'B'RDR2U'B'LR'B'F2D2UF2L'
BR2F'B'R'D'R'U2B'F2D2R'F2D'F'D2R2B'L2R'UB'R2L'D
If you separate the moves by a space each:
R2 L' F2 U2 D' R2 L2 F L' D2 U R B D' U2 L B2 L U B2 D U2 R' D2 U'
B R D2 F U2 B' R2 F2 B' U' L' R2 B U2 R' D B' F' U2 R' B' L R D2 R2
B2 R2 U D' B R D' R L2 D2 L2 R B2 F U' F2 B2 U' F U' D F R2 U2 B'
Notice, that all these outputs consists of 25 moves, but have different lengths, because of the optional suffixes. It's not allowed to print a space, when either 2 or ' are uses as suffix. You have to print L2UR2F'R'U2 or L2 U R2 F' R' U2. L2U R2F'R'U2 is not allowed.
Did you mean
UR 2is not allowed?U R2should be allowed, I think, since spaces between moves makes sense. – mbomb007 – 2015-03-05T19:19:20.137@mbomb007 I mean stuff like
L2U R2F'R'U2.Uhas no optional suffix and therefore shouldn't have a space. A space should not be a replacement for the optional suffix. – Jakube – 2015-03-05T19:35:13.450What if there are spaces between every move? Could we output
U F2 L D2 R'..., for example? In this case, there isn't an extra space, which I think should be okay according to your rule. – mbomb007 – 2015-03-05T19:37:17.963@mbomb007 Yes, I will put it into the description. – Jakube – 2015-03-05T19:39:05.373
Isn't the 2 before the letter? o.O – Oliver Ni – 2017-07-08T18:00:45.783
@tfbninja Yes, of course. – Jakube – 2018-03-01T00:58:50.320