This Challenge is to solve Question E, Driving the Rover, of the USC ACM Fall 2012 Contest.
The Rover is sent a Series of commands. Your task is to emulate the Rover response to the sequence and determine its "final position", [x,y]. The "final position" is the Rover location 1 second after the final command.
Initial conditions are Rover Stopped and Facing +Y. Commands are processed at 1 second intervals
Commands and their attributes: FORWARD: Starts rolling forward at 1 cm/s BACKWARDS: Roll backwards at 1 cm/s FASTER: Increase forward speed by 1 cm/s up to 5 cm/s SLOWER: Decrease forward speed by 1 cm/s down to 0 cm/s. At 0 cm/s Rover is "Stopped" STOP: Halts rover movement RIGHT: Turn rover 90 degrees to the right LEFT: Turn the rover 90 degrees to the left NOOP: No change in anything
Commands FORWARD, BACKWARDS, RIGHT, LEFT only take effect if the rover is stopped. A moving rover ignores these commands.
Commands FASTER and SLOWER only take effect if the rover is moving forward.
Input: [Cell array of Rover Commands]
Output: [x, y ]; Final Position 1 second after last command;
The full USC data file
Example:
Input: {'FORWARD' 'RIGHT' 'STOP' 'RIGHT' 'FORWARD' 'FASTER'}
Output: [3 2] as the first RIGHT is ignored
A Contest Drive solution. Time to Solve: 9 minutes. Start.
This is predecessor to the Martian Pits Challenge.
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers8
Suggested Problems
-
Find the numeric mean of the prime numbers in a matrix.
9160 Solvers
-
Find state names that start with the letter N
1494 Solvers
-
1069 Solvers
-
Find Index of maximum Value and maximum Value of a vector
170 Solvers
-
Reverse the elements of an array
1135 Solvers
More from this Author306
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!