Evan's Cube

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem type

A Rubik's Cube is a 3-D combination puzzle. The cube consists of six faces, each of which is covered by nine stickers. The stickers are one of six solid colours: white, red, blue, orange, green, and yellow. Initially, the cube is "scrambled", meaning that each of the nine stickers on each face are a random colour. The goal of the Rubik's Cube is to "solve" it, making each face of the cube one specific colour, through a series of rotations.

There are exactly six faces to a Rubik's Cube. Each face can be "rotated" clockwise or counter-clockwise. We will denote each face a number between one and six, and C for a clockwise rotation and W for a counter-clockwise rotation. If we imagine a cube facing directly towards us, face 1 denotes the face facing towards us, face 2 the one facing to the left, face 3 the one facing away, face 4 the one facing to the right, face 5 the one facing down, and face 6 the one facing up. When we rotate a face clockwise, we are imagining as if we are looking directly at the face, and rotating the face to the right. The opposite is true for a counter-clockwise rotation.

You are given a scrambled Rubik's Cube and a series of Q rotations that were performed on it. Can you determine if the cube is "solved" after this series of rotations?

Online Rubik's Cube Simulator

Input Specification

The first 3 lines will each contain 3 characters. These will denote the colours of the nine stickers on face 1. The characters will be one of W,R,B,O,G,Y, denoting white, red, blue, orange, green, and yellow, respectively.

The next 3 lines will follow a similar format as the first 3 lines. These will denote face 2.
The next 3 lines will denote the colours on face 3.
The next 3 lines will denote the colours on face 4.
The next 3 lines will denote the colours on face 5.
The next 3 lines will denote the colours on face 6.

All faces are given as if you are facing it directly. For faces 1-4, they are given with face 5 facing down and face 6 facing up. For faces 5 and 6, they are given with face 1 facing up and face 3 facing down.

It is guaranteed that there will be exactly nine of each of the six colours.

The next line will contain the integer Q, the number of rotations that were performed. There will be at most 50 operations performed on the cube.

The next Q lines will each contain a string of the form FD. F is the face that is being rotated, and D is either C for a clockwise rotation or W for a counter-clockwise rotation.

Note that in this problem, the middle section cannot be rotated directly, only the faces.

Output Specification

Output Solved! if the Rubik's Cube is solved after the rotations, or Boo! if it is not solved.

Constraints

Note: you do NOT need to pass the sample test cases to pass some of the subtasks.

Subtask 1 [10%]

There will be no rotations. (Q = 0)

Subtask 2 [20%]

There will be at most one rotation. (Q \le 1)

Subtask 3 [70%]

No additional constraints.

Sample Input 1

WWW
WWW
WWW
RRR
RRR
RRR
BBB
BBB
BBB
OOO
OOO
OOO
GGG
GGG
GGG
YYY
YYY
YYY
1
1C

Sample Output 1

Boo!

Explanation For Sample 1

The cube was initially solved, but the one clockwise rotation on face 1 unsolved it. Boo!

Sample Input 2

RRB
WWW
RRB
YYY
RRB
YYY
GOO
YYY
GOO
WWW
GOO
WWW
BBO
BBO
BBO
RGG
RGG
RGG
3
6C
5W
1W

Sample Output 2

Solved!

Comments

There are no comments at the moment.