PROBLEM STATEMENT
Write a method that will be used in a simulation of a rolling die.
A die is a cube-shaped object used in many games. Each face of the die shows a
different number from 1 to 6. Numbers on opposite sides of the die always add
up to 7. So for example, the 2 must be across from the 5.
For this problem, assume the die is sitting on a table. We will label the
faces of the die "top", "bottom", "left", "right", "front", and "back".
Looking at the die so that the front face is facing towards you, the left,
right, and back faces are facing to the left, to the right, and away from you,
respectively. Initially, the top face shows the number 1, the front face shows
the number 2, and the right face shows the number 3.
We model the rolling of the die as a series of "turns" that are applied to the
die. The possible turns are:
'B' represents tipping the die backwards, so that the top face becomes the new
back face.
'F' represents tipping the die forwards, so that the top face becomes the new
front face.
'R' represents tipping the die to the right, so that the top face becomes the
new right face.
'L' represents tipping the die to the left, so that the top face becomes the
new left face.
'C' represents spinning the die clockwise, so that the top face remains the top
face, and the front face becomes the new left face.
'A' represents spinning the die anticlockwise, so that the top face remains the
top face, and the front face becomes the new right face.
Write a method simulate that returns the value on the top face after a series
of turns is applied to the die. The String represents the turns that are
applied. For example, if the String is "ARC", this means the die is first spun
anticlockwise, then tipped to the right, and then spun clockwise.
DEFINITION
Class: RollDie
Method Name: simulate
Parameters: String
Returns: int
Method signature (be sure your method is public): int simulate(String turns);
NOTES
TopCoder will ensure the validity of the inputs. Inputs are valid if all of
the following criteria are met:
* turns contains between 0 and 50 characters, inclusive
* turns contains only the characters 'B', 'F', 'R', 'L', 'C', and 'A'
EXAMPLES
Suppose turns = "FAR".
Before the first turn is applied, the top face shows a 1, the front face shows
a 2, and the right face shows a 3.
First, the die is tipped forwards. This moves the 1 to the front face. The
previous back face, which showed 5, becomes the new top face.
Next, the die is spun anticlockwise. Now, the top face is still 5, but the 1
has moved to the right face.
Finally, the die is tipped to the right. The 5 moves to the right face. The
previous left face, which showed 6, becomes the new top face.
Hence the method returns 6.
more examples:
if turns = "CL", then return 5
if turns = "BCCCCRRRRBBBBACACRLRLFBFB", then return 2
if turns = "", then return 1