A move sequence is a sequence of moves (turns) on a Rubik's Cube (for the notation look down below). Beside the empty move sequence, there are many other other move sequences, that have no effect on the cube at all. We call these move sequences identity sequences.
Some of these identity sequences are obvious to determine, like
U2 R R' U2 or
U D2 U' D2. In the first one, two random moves are done
U2 R and afterwards immediately undone
R' U2. The second one is similar. First two random moves
U D2 and afterwards they are undone, but in reversed order
U' D2. This only works, because the move
U effects only the pieces of the upper layer and the move
D2 only effects pieces of the lower layer. You can see a visualization of these two move sequences.
Other identity sequences may be not obvious at all. For instance the sequence
R' U' R' F' U F U' R' F R F' U' R U2 R. It pretty long, but also has no effect at the cube at all.
A move describes the turn of one layer of one of the six faces of the cube. A move consist of one letter representing the face followed by an optional suffix representing the turn angle.
The letters and their corresponding faces are U (Up - the side facing upwards), D (Down - the side facing downwards), R (Right - the side facing to the right), L (Left - the side facing to the left), F (Front - the side facing you) and B (Back - the side facing away from you).
If there is no suffix, the face is turned 90-degree clockwise, the suffix
' means, the face is turned 90-degree counterclockwise, and the suffix
2 means, the face is turned 180-degree clockwise.
It you have any problems with the notation, just use http://alg.cubing.net, where you can visualize such move sequences.
Your task is to write a program, that determines if a move sequences is an identity or not.
You may write a full program or a function. It should receive a string containing a move sequence (moves are separate by spaces) as input (via STDIN, command-line argument, prompt or function argument), and output (via return value or STDOUT) a Boolean value or a corresponding integer (True - 1 - identity sequence/ False - 0 - not identity sequence).
If you suffix
' creates problems in your programming language, you may use a different symbol, but not at digit.
R F2 U3 is not allowed.
This is codegolf, therefore the shortest code (in bytes) wins.
"" -> True "U2 R R' U2" -> True "U D2 U' D2" -> True "U2 R U2 R'" -> False "R' U' R' F' U F U' R' F R F' U' R U2 R" -> True "L'" -> False "B B2 B' B2" -> True "D D2 D'" -> False "R F' D2 U B' F2 B' U2 D2 F2 B2 U F R'" -> True "D2 U' R2 U F2 D2 U' R2 U' B' L2 R' B' D2 U B2 L' D' R2" -> False "R U R' U' R' F R2 U' R' U' R U R' F' R2 U R2 U' R2 U' D R2 U' R2 U R2 D'" -> True "R U R' U' R' F R2 U' R' U' R U R' F' R2 U' R2 U R2 U' D R2 U' R2 U R2 D'" -> False "B2 F2 U' F2 U R2 F2 U2 B D' R' D' R2 D' F2 U' F U R2 U R B D B D2 L2 D' F2 U D' R' D B R2 D2 F2 R' F2 D2" -> True "R U2 R' U R' U2 R U2 R U R' U' R' U R U2" -> False "U F B' R' U F' R U' F' B L U' F L'" -> False "R2 U' R' U' R U R U R U' R" -> False "R' F R' B2 R F' R' B2 R2" -> False
R F2 U3? \$\endgroup\$
U3, than you could simply cast the suffix into a digit. \$\endgroup\$
R2 D2. \$\endgroup\$
That is F(orward), B(ackward), L(eft), R(ight), U(p), D(own)\$\endgroup\$