|
| 1 | +# Challenge: Toy Robot Simulator |
| 2 | + |
| 3 | +## Description |
| 4 | + |
| 5 | +- The application is a simulation of a toy robot moving on a square tabletop, of dimensions 5 units x 5 units. |
| 6 | +- There are no other obstructions on the table surface. |
| 7 | +- The robot is free to roam around the surface of the table, but must be prevented from falling to destruction. Any movement that would result in the robot falling from the table must be prevented, however further valid movement commands must still be allowed. |
| 8 | + |
| 9 | +#### Create an application that can read in commands of the following form |
| 10 | + |
| 11 | + PLACE X,Y,F |
| 12 | + MOVE |
| 13 | + LEFT |
| 14 | + RIGHT |
| 15 | + REPORT |
| 16 | + |
| 17 | +- `PLACE` will put the toy robot on the table in position X,Y and facing NORTH, |
| 18 | + SOUTH, EAST or WEST. |
| 19 | +- The origin (0,0) can be considered to be the SOUTH WEST most corner. |
| 20 | +- The first valid command to the robot is a `PLACE` command, after that, any |
| 21 | + sequence of commands may be issued, in any order, including another `PLACE` |
| 22 | + command. The application should discard all commands in the sequence until a |
| 23 | + valid `PLACE` command has been executed. |
| 24 | +- `MOVE` will move the toy robot one unit forward in the direction it is |
| 25 | + currently facing. |
| 26 | +- `LEFT` and `RIGHT` will rotate the robot 90 degrees in the specified direction |
| 27 | + without changing the position of the robot. |
| 28 | +- `REPORT` will announce the X,Y and F of the robot. This can be in any form, |
| 29 | + but standard output is sufficient. |
| 30 | +- A robot that is not on the table can choose to ignore the `MOVE`, `LEFT`, |
| 31 | + `RIGHT`, and `REPORT` commands. |
| 32 | +- Input can be from a file, or from standard input, as the developer chooses. |
| 33 | +- Provide test data to exercise the application. |
| 34 | + |
| 35 | +## Constraints |
| 36 | + |
| 37 | +The toy robot must not fall off the table during movement. This also includes the initial placement of the toy robot. |
| 38 | +Any move that would cause the robot to fall must be ignored. |
| 39 | + |
| 40 | +## Example Input and Output: |
| 41 | + |
| 42 | +*Example 1* |
| 43 | + |
| 44 | + PLACE 0,0,NORTH |
| 45 | + MOVE |
| 46 | + REPORT |
| 47 | + |
| 48 | + Output: 0,1,NORTH |
| 49 | + |
| 50 | + |
| 51 | +*Example 2* |
| 52 | + |
| 53 | + PLACE 0,0,NORTH |
| 54 | + LEFT |
| 55 | + REPORT |
| 56 | + |
| 57 | + Output: 0,0,WEST |
| 58 | + |
| 59 | + |
| 60 | +*Example 3* |
| 61 | + |
| 62 | + PLACE 1,2,EAST |
| 63 | + MOVE |
| 64 | + MOVE |
| 65 | + LEFT |
| 66 | + MOVE |
| 67 | + REPORT |
| 68 | + |
| 69 | + Output: 3,3,NORTH |
| 70 | + |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +Interview question by [Jon Eaves][jon_eaves] (he acknowledges it is not that original). |
| 75 | + |
| 76 | +[jon_eaves]: https://joneaves.wordpress.com/2014/07/21/toy-robot-coding-test/ |
| 77 | + |
0 commit comments