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
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
BBand all their combinations using the optional suffixes like
These move pairs are banned, because they can easily reduced to 1 or 0 moves.
U2Uhas the same effect as
R'Rthe same effect as
Three consecutive moves must not be of the same letter group. The letter groups are
FB. This rule additionally bans the consecutive moves
BFBand all their combinations using the optional suffixes like
The groups sort the faces by their move axis.
Dare in the same group, because both turn around the same axis. Therefore an
Umove doesn't influence the pieces of the
Dface, and a
Dmove doesn't influence pieces of the
Uface. Therefore the two moves can be exchanged,
UDUhas the same effect as
UUD, and this can be reduced to
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.
Calling the script / function 3 times should print / return something like:
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
' are uses as suffix. You have to print
L2 U R2 F' R' U2.
L2U R2F'R'U2 is not allowed.