You are working with a computer simulation of a mobile robot. The robot moves on an plane, and its movements are described by a command string consisting of one or more of the following letters:
G
instructs the robot to move forward one stepL
instructs the robot to turn leftR
instructs the robot to turn right
The robot CANNOT go backwards - poor robot. After running all of the movement commands, you want to know if the robot returns to its original starting location.
For instance, the command GRGRGRG
would make the robot return to its original starting location.
- Copy this markdown and paste in your own, privte gist
- In your private gist, fill out the questions below
- Submit by the due time as instructed in Zoom
Do not publish your code on a public repl.it or repo or other public means.
With only the information provided, what data is safe to extrapolate, based on the information given?
I would assume the robot can turn in a circle with out traveling any distance. For instance, R, R
would spin the robot around, and thus, R, R, G
would be a way for the robot to spin and travel "backwards" from it's initial orientation, like a roomba or a tank.
Well, we know this bot is on a plane, and therefore can measure it's distance traveled on the x/y axes. We can also find the direction it has traveled based on how many L
's or R
's were input.
- Searching of Data
- Sorting of Data
- Pattern Recognition
Because this problem deals with a pattern input of
G, L, R
I would think it's safe to assume it would utilize a pattern to solve. - Build/Navigate a Grid Because this problem already states the robot will travel on a plane, I would assume it would be safe to use a grid for this project.
- Math
- Language API knowledge
- Optimization
I would assume an object would be the easiest for me to organize this problem. I don't know if front end is a familiar with different types of data structures as backend. If I was more versed, I might used a graph or binary tree.
robot = { north: 0, east: 0, south: 0, west: 0, orientation: 'north' }
function inputG() { robot[robot.orientation] += 1 }
function inputR() { var directions = ['north', 'east', 'south', 'west']; if (robot.orientation === 'west') { robot.orientation === 'north' } else { robot.orientation === directions[directions.indexOf(robot.orientation) += 1] } }
function inputL() { var directions = ['north', 'east', 'south', 'west']; if (robot.orientation === 'north') { robot.orientation === 'west' } else { robot.orientation === directions[directions.indexOf(robot.orientation) -= 1] } }
function checkLocation() { if (robot.north -= robot.south === 0 && robot.west -= robot.east === 0) { return 'home' } else { return 'lost' } }