|
| 1 | +# Martian Robots |
| 2 | + |
| 3 | +Hi! If you are reading this is because we would love you to be part of the Engineering team at |
| 4 | +Draftea and keep moving forward in the coding challenge. We ask you to please share your private |
| 5 | +project with @joecohens @danteay @peopledraftea when you have finished it. |
| 6 | + |
| 7 | +## The Problem |
| 8 | + |
| 9 | +The surface of Mars can be modelled by a rectangular grid around which robots are able to move |
| 10 | +according to instructions provided from Earth. You are to write a program that determines each |
| 11 | +sequence of robot positions and reports the final position of the robot. A robot position consists |
| 12 | +of a grid coordinate (a pair of integers: x-coordinate followed by y-coordinate) and an orientation |
| 13 | +(N, S, E, W for north, south, east, and west). A robot instruction is a string of the letters "L", |
| 14 | +"R", and "F" which represent, respectively, the instructions: |
| 15 | + |
| 16 | +- Left : the robot turns left 90 degrees and remains on the current grid point. |
| 17 | +- Right : the robot turns right 90 degrees and remains on the current grid point. |
| 18 | +- Forward : the robot moves forward one grid point in the direction of the current orientation and |
| 19 | + maintains the same orientation. |
| 20 | + |
| 21 | +The direction North corresponds to the direction from grid point (x, y) to grid point (x, y+1). |
| 22 | +There is also a possibility that additional command types may be required in the future and |
| 23 | +provision should be made for this. |
| 24 | + |
| 25 | +Since the grid is rectangular and bounded (... yes Mars is a strange planet), a robot that moves |
| 26 | +"off" an edge of the grid is lost forever. However, lost robots leave a robot "scent" that |
| 27 | +prohibits future robots from dropping off the world at the same grid point. The scent is left at |
| 28 | +the last grid position the robot occupied before disappearing over the edge. An instruction to move |
| 29 | +"off" the world from a grid point from which a robot has been previously lost is simply ignored by |
| 30 | +the current robot. |
| 31 | + |
| 32 | +## The Input |
| 33 | + |
| 34 | +The first line of input is the upper-right coordinates of the rectangular world, the lower-left |
| 35 | +coordinates are assumed to be 0, 0. The remaining input consists of a sequence of robot positions |
| 36 | +and instructions (two lines per robot). A position consists of two integers specifying the initial |
| 37 | +coordinates of the robot and an orientation (N, S, E, W), all separated by whitespace on one line. |
| 38 | + |
| 39 | +A robot instruction is a string of the letters "L", "R", and "F" on one line. Each robot is |
| 40 | +processed sequentially, i.e., finishes executing the robot instructions before the next robot |
| 41 | +begins execution. The maximum value for any coordinate is 50. All instruction strings will be less |
| 42 | +than 100 characters in length. |
| 43 | + |
| 44 | +## The Output |
| 45 | + |
| 46 | +For each robot position/instruction in the input, the output should indicate the final grid |
| 47 | +position and orientation of the robot. If a robot falls off the edge of the grid the word "LOST" |
| 48 | +should be printed after the position and orientation. |
| 49 | + |
| 50 | +### Sample Input |
| 51 | + |
| 52 | +The input is a text file: |
| 53 | + |
| 54 | +```text |
| 55 | +5 3 |
| 56 | +1 1 E |
| 57 | +RFRFRFRF |
| 58 | +3 2 N |
| 59 | +FRRFLLFFRRFLL |
| 60 | +0 3 W |
| 61 | +LLFFFLFLFL |
| 62 | +``` |
| 63 | + |
| 64 | +### Sample Output |
| 65 | + |
| 66 | +```text |
| 67 | +1 1 E |
| 68 | +3 3 N LOST |
| 69 | +2 3 S |
| 70 | +``` |
0 commit comments