The Rubik's Cube is often said to be the best-selling toy of all time
(given suitable restrictions). Invented in 1974 by Ernő Rubik, a
Hungarian sculptor and professor of architecture, it takes the
appearance of a large cube divided into
If one holds the cube such that one of the faces is pointed directly at
oneself, it is possible to assign a notation to the faces of the cube –
F
for front (the face directly visible), U
for up, D
for down, L
for
left, R
for right, and B
for back (the face opposite the front face).
From this it is only a small step to a notation for rotations. A
'
). For example, R'D2F
means to rotate the right face counterclockwise, then rotate the bottom
face
In this problem, a configuration of the Rubik's cube will be represented by a net, such as the following:
1 1 1
1 1 1
1 1 1
2 2 2 3 3 3 4 4 4 5 5 5
2 2 2 3 3 3 4 4 4 5 5 5
2 2 2 3 3 3 4 4 4 5 5 5
6 6 6
6 6 6
6 6 6
Each U
face and the leftmost block forms the L
face. Similarly, the centre block represents the F
face, the block to
the right represents the R
face, the rightmost block represents the B
face, and the bottom block represents the D
face. This configuration is
solved because all the stickers on each face match. On the other hand,
the following configuration:
3 1 1
3 1 1
3 1 1
2 2 2 6 3 3 4 4 4 5 5 1
2 2 2 6 3 3 4 4 4 5 5 1
2 2 2 6 3 3 4 4 4 5 5 1
5 6 6
5 6 6
5 6 6
requires a clockwise twist of the L
face in order to restore to the
solved configuration above. Note that it is not necessarily the numerals
W R B O G Y
for white, red, blue, orange, green, and
yellow, a popular set of colours for the stickers.
Given a configuration of the Rubik's cube, you are to find a sequence of moves that restores it to a "solved" configuration.
Input Specification
Nine lines in the format described above.
Output Specification
A string on a single line in the format given, that is, matching the
regular expression ^([UDLRFB][2']?)*$
, no longer than
Sample Input
3 1 1
3 1 1
3 1 1
2 2 2 6 3 3 4 4 4 5 5 1
2 2 2 6 3 3 4 4 4 5 5 1
2 2 2 6 3 3 4 4 4 5 5 1
5 6 6
5 6 6
5 6 6
Sample Output
L
Scoring
It is known (Rokicki et al., 2010) that the exact upper bound on the
number of moves required to solve any legal configuration of the Rubik's
cube is
Comments
For faces that are not the front face, what are "clockwise" and "counterclockwise" relative to?
As one would expect by convention, the normal vector.
which normal vector
The time limit....
The AC solution takes 0.021s worst case.