Hide

Problem F
Magic Bean

\includegraphics[width=0.35\textwidth ]{magicbeancube2.png}    \includegraphics[width=0.35\textwidth ]{newimage.png}

A β€œMagic Bean” is a combination fidget toy and puzzle, with 30 colored beads moving in three circular tracks. In its solved state, the upper circle contains ten indistinguishable orange beads, the lower left circle contains ten indistinguishable grey beads, and the lower right circle contains ten indistinguishable red beads. The beads can be rotated in each circle. In addition, there is a fourth circle in the middle that can be rotated, and in doing so exchanges consecutive triples of beads among the circles.

Your brother just borrowed your Magic Bean and arbitrarily rotated those circles, scrambling the beads. Your job is to solve the puzzle, by finding a sequence of valid rotations of the four circles that leads back to the solved state. You need not find the shortest such solution, but your solution should use no more than $240$ moves. The provided input will be the state of the puzzle after applying some sequence of at most $240$ moves.

Input

Input consists of exactly three lines. Each line contains a string of length ten, consisting only of the characters o, g and r. The first line describes the ten beads in the top circle, the second describes the lower-left circle, and the third describes the lower-right circle.

The character o designates an orange bead, g a gray bead, and r a red bead. The beads are listed in clockwise order, numbered according to the diagram.

The input configuration is the result of applying at most $240$ moves on a solved puzzle.

Output

Output a single integer $k$, with $0\le k\le 240$, which is the number of moves you needed to solve the puzzle.

Next, if $k>0$, output the $k$ moves on $k$ lines, with one move per line, in order. Each move consists of a single character, specifying the circle to be rotated, followed immediately by a single digit specifying how far to rotate the circle in a clockwise direction. The top circle is specified with β€˜o’, the lower left circle with β€˜g’, the lower right circle with β€˜r’, and the center circle with β€˜c’. For the first three circles, the digit specifying the rotation has a value from 1 to 9; for the central circle, it has a value from 1 to 2.

The following two images show the input positions for the two samples.

\includegraphics[width=0.35\textwidth ]{t2.png}    \includegraphics[width=0.35\textwidth ]{t3.png}
Sample Input 1 Sample Output 1
gggooooooo
rrrggggggg
ooorrrrrrr
1
c2

Sample Input 2 Sample Output 2
ggooooooog
rrrggggggg
ooorrrrrrr
2
o1
c2

Please log in to submit a solution to this problem

Log in