A simple way to scramble a 2x2x2 Rubik's cube is to make a sequence random moves. This is not how official scrambles are done, but can get pretty close to a uniform distribution of all possible scramble states. Due to the way a 2x2 only has two layers, doing one turn on one face is equivalent (without considering the puzzle's orientation in space) to doing the same direction turn on the opposite face. For example, turning the top face clockwise moves all the pieces in relation to each other the same way turning the bottom face clockwise does. So scrambles only need to turn the top (U), right (R), and front (F) faces.
For this challenge, your program must generate a string that represents a sequence of 16 moves. A move is represented by a face, one of the letters U
, R
, F
, followed by a direction: clockwise (empty string or space
), counterclockwise (apostrophe '
), or 180 degrees (2
). The turn and direction should be chosen uniformly at random, however two consecutive moves cannot turn the same face, For example a scramble cannot contain R' R2
. So the first move should have a 1/3 chance for each face, but there should be a 50/50 chance for the chosen face after the first move. Moves are separated by a space.
Example scramble:
U F' R2 F' R' F R F2 U' F R2 F U2 F' U2 F2
F 2R 'U 'R
? \$\endgroup\$