Identity sequences on the Rubik's Cube 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. 



Move Notation

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. 

The Challenge

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. 

Test Cases

"" -&gt; True
"U2 R R' U2" -&gt; True
"U D2 U' D2" -&gt; True
"U2 R U2 R'" -&gt; False
"R' U' R' F' U F U' R' F R F' U' R U2 R" -&gt; True
"L'" -&gt; False
"B B2 B' B2" -&gt; True
"D D2 D'" -&gt; False
"R F' D2 U B' F2 B' U2 D2 F2 B2 U F R'" -&gt; True
"D2 U' R2 U F2 D2 U' R2 U' B' L2 R' B' D2 U B2 L' D' R2" -&gt; 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'" -&gt; 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'" -&gt; 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" -&gt; True
"R U2 R' U R' U2 R U2 R U R' U' R' U R U2" -&gt; False
"U F B' R' U F' R U' F' B L U' F L'" -&gt; False
"R2 U' R' U' R U R U R U' R" -&gt; False
"R' F R' B2 R F' R' B2 R2" -&gt; False
Haskell, 263 261 247 243 characters

c[x]=[x]
c(x:"2")=[x,x]
c(x:_)=[x,x,x]
s!a@[x,y,z]=case s of
 'R'|x&gt;0-&gt;[x,-z,y]
 'B'|y&gt;0-&gt;[z,y,-x]
 'U'|z&gt;0-&gt;[-y,x,z]
 'L'|x&lt;0-&gt;[x,z,-y]
 'F'|y&lt;0-&gt;[-z,y,x]
 'D'|z&lt;0-&gt;[y,-x,z]
 _-&gt;a
r=[-2..2]
i=mapM id[r,r,r]
f w=i==foldr(map.(!))i(c=&lt;&lt;words w)


Rather straightworward algorithm; each cubelet is made out of 1,2,4 or 8 chunks encoding its position and orientation; 4 chunks per edge cubelet, 8 per corner cubelet, 7 cubelets are stationary.

c chomps each word of the input into a sequence of CW turns, and ! sends each chunk according to a turn. i is the identity position. f is the main function.

I'm not too happy with the chomp function, but I can't seem to find a way to shorten it either (@Nimi did, however)