Toy Robot Coding Puzzle

PLACE X,Y,F
MOVE
LEFT
RIGHT
REPORT

Constraints:

Example Input and Output:

a)

PLACE 0,0,NORTH
MOVE
REPORT
Output: 0,1,NORTH

b)

PLACE 0,0,NORTH
LEFT
REPORT
Output: 0,0,WEST

c)

PLACE 1,2,EAST
MOVE
MOVE
LEFT
MOVE
REPORT
Output: 3,3,NORTH

Installation

Install Crystal

Usage

To build an app run:

shards build

To run:

bin/bin_truck_simulator

Just input commands in STDIN, report results goes to STDOUT and errors to STDERR. Exit using CTRL+D.

Also you can use it using Unix pipes. For example:

$ cat spec/examples/example_a | bin/toy_robot_crystal
0,1,NORTH

$ cat spec/examples/example_b | bin/toy_robot_crystal
0,0,WEST

$ cat spec/examples/example_c | bin/toy_robot_crystal
3,3,NORTH

Testing

To run specs run:

$ crystal spec

Design decisions