Statistics

Problem Statement for "SpaceDrone"

Problem Statement

Our unmanned space vehicle responds to command sequences where each command is a single uppercase character that describes an action relative to the current location and orientation of the drone:
  • F -- move forward one unit
  • Y -- yaw 90 degrees counterclockwise as seen from the top of the drone
  • R -- roll 90 degrees counterclockwise as seen from the back of the drone
Y causes a rotation around the axis through the top and bottom of the drone. R causes a rotation around the axis through the back and front of the drone. Initially the drone is located at x=0,y=0,z=0. It is oriented so that its back-to-front axis is in the positive x direction, and its bottom to top axis is in the positive y direction. Create a class SpaceDrone that contains a method whereAmI that takes a command sequence as input and returns the x coordinate of the resulting position.

Definition

Class:
SpaceDrone
Method:
whereAmI
Parameters:
String
Returns:
int
Method signature:
int whereAmI(String commands)
(be sure your method is public)

Notes

  • Notice that the orientation of the xyz coordinate system is irrelevant since you only need to return the final x coordinate.

Constraints

  • commands contains between 1 and 50 characters inclusive
  • each character in commands is uppercase F, Y, or R

Examples

  1. "FFF"

    Returns: 3

    The drone goes forward along the x axis 3 units, ending at (3,0,0)

  2. "YYRRYRY""

    Returns: 0

    The drone has done multiple rotations, but has never moved from (0,0,0)

  3. "YFYFY"

    Returns: -1

  4. "RFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFYF"

    Returns: 47

  5. "YFRFFYFFFRFFFFYFFFFF"

    Returns: 5

  6. "YYYYYYYYYYYFYFFYFFFYFFFFYFFFFF"

    Returns: -2

  7. "FYFFRFFFRFFFFYFFFFFYFFFFFF"

    Returns: 6

  8. "FYFFRFFFRFFFFYFFFFFYFFFFFFRRYFFFFFFFFF"

    Returns: 15

  9. "YYFFFFFRYYFF"

    Returns: -3

  10. "FRYRRYYF"

    Returns: 1

  11. "FRFFYFFFRFFFFRFFFFFYFFFFFFYF"

    Returns: 9

  12. "YFRRYFFFY"

    Returns: 3

  13. "RFYFFRFFFYFFFFRFFFFFFFFYFFFFFFFYFFFYFFFFYFFFFFF"

    Returns: 4

  14. "YYRFYFFRFFFYFFFFRFFFFFFFFYFFFFFFFYFFFYFFFFYFFFFFF"

    Returns: -4

  15. "YFYFYFYFRYFYFYFYFRYFYFYFYFRYFYFYFYFR"

    Returns: 0

  16. "YRYFYFYFYFRRYFYFYFYF"

    Returns: 0

  17. "RYRFYYFFRRYFFFYRRRFYFFFYYFYFRRYRFFRFRRRRRYRFRRRFRF"

    Returns: -1

  18. "RRYRFRYFRRYRYRYYRFFFFRYFFRRFFYFYYRFFFYFRYFRFFFRYFF"

    Returns: 1

  19. "YRFRRFFFYRFYYFYRFYFFYRFRRFFFYRFFYRRFYFFRRFYFFYRF"

    Returns: -3

  20. "FFRYFFFFRYYYRFRFRYYRRRRRRYRRFYRFRYFFYYRFYRFYFRRFFY"

    Returns: 0

  21. "FYFFYFYRRYYRFRFYRRYRRFYYFFYRYFYRRFFRRYYFFRYYFRFYYY"

    Returns: -2

  22. "YYFYRRFRFFYRYFRRYRRFFYYRYFRYFYRYRFFYRFFFRYRRFFRFYY"

    Returns: 4

  23. "RYYYFYFYRRFFYRRRYFYYYYFFFYFYRYRYFRRFYRFFFRYRYFYFFF"

    Returns: 1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: