Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jameshopkins/martian-robots
π½ Coding challenge
https://github.com/jameshopkins/martian-robots
Last synced: 12 days ago
JSON representation
π½ Coding challenge
- Host: GitHub
- URL: https://github.com/jameshopkins/martian-robots
- Owner: jameshopkins
- Created: 2014-06-19T15:20:04.000Z (over 10 years ago)
- Default Branch: node
- Last Pushed: 2023-03-06T04:24:19.000Z (over 1 year ago)
- Last Synced: 2024-03-15T06:02:51.541Z (8 months ago)
- Language: LiveScript
- Homepage:
- Size: 180 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Martian Robots
==============### The Problem
The surface of Mars can be modelled by a rectangular grid around which robots are able to move according to instructions provided from Earth. You are to write a program that determines each sequence of robot positions and reports the final position of the robot. A robot position consists of a grid coordinate (a pair of integers: x-coordinate followed by y-coordinate) and an orientation (N, S, E, W for north, south, east, and west). A robot instruction is a string of the letters βLβ, βRβ, and βFβ which represent, respectively, the instructions:
* **Left**: the robot turns left 90 degrees and remains on the current grid point.
* **Right**: the robot turns right 90 degrees and remains on the current grid point
* **Forward**: the robot moves forward one grid point in the direction of the current orientation and maintains the same orientation.The direction North corresponds to the direction from grid point (x, y) to grid point (x, y+1). There is also a possibility that additional command types may be required in the future and provision should be made for this.
Since the grid is rectangular and bounded (...yes Mars is a strange planet), a robot that moves βoffβ an edge of the grid is lost forever. However, lost robots leave a robot βscentβ that prohibits future robots from dropping off the world at the same grid point. The scent is left at the last grid position the robot occupied before disappearing over the edge. An instruction to move βoffβ the world from a grid point from which a robot has been previously lost is simply ignored by the current robot.
### The Input
The first line of input is the upper-right coordinates of the rectangular world, the lower-left coordinates are assumed to be 0, 0. The remaining input consists of a sequence of robot positions and instructions (two lines per robot). A position consists of two integers specifying the initial coordinates of the robot and an orientation (N, S, E, W), all separated by whitespace on one line. A robot instruction is a string of the letters βLβ, βRβ, and βFβ on one line. Each robot is processed sequentially, i.e., finishes executing the robot instructions before the next robot begins execution. The maximum value for any coordinate is 50. All instruction strings will be less than 100 characters in length.5 3
1 1 E
RFRFRFRF3 2 N
FRRFLLFFRRFLL0 3 W
LLFFFLFLFL### The Output
For each robot position/instruction in the input, the output should indicate the final grid position and orientation of the robot. If a robot falls off the edge of the grid the word βLOSTβ should be printed after the position and orientation.1 1 E
3 3 N LOST
2 3 S## Install
### To run
npm start '5 3\n1 1 E\nRFRFRFRF\n\n3 2 N\nFRRFLLFFRRFLL\n\n0 3 W\nLLFFFLFLFL'### To test
npm test