A story for the robot-simulator exercise

One of my favorite exercises that i’ve mentored a lot in the past. In addition to the story, the description has also received a facelift.

Introduction

The testing floor in the robot factory was quiet, filled only with the soft hum of machinery. You stand by, watching as your robot, the result of months of hard work, is placed on the grid. It isn’t just the robot being tested, but the program you are writing to control its movements. Your program will guide the robot through a series of instructions, and the testing facility will verify whether the robot ends up in the correct position and facing the right direction.

The robot stands at a random position, waiting for its next set of commands. With each instruction, it will move, turn, or advance on the grid. Will it follow the commands correctly? The test facility will soon provide the answer.

Instructions

Write a robot simulator.

The task is to simulate the movement of a robot on a hypothetical infinite grid, where the robot can perform three actions:

  • turn right
  • turn left
  • advance forward one unit

The robot starts at a specific set of coordinates {x, y} (e.g., {3, 8}), facing one of four possible directions: north, east, south, or west. The x part of the coordinates increases when moving east, and the y part increases when moving north.

The robot will receive a sequence of instructions consisting of the letters “R”, “L”, and “A”, each representing one of the three actions. After executing all the instructions the testing facility verifies the robot’s new position, and in which direction it is facing.

Example

A robot starts at {7, 3} facing north and executes the instructions “RAALAL”:

  1. R: Turns right and is now facing east.
  2. A: Advances to {8, 3}.
  3. A: Advances to {9, 3}.
  4. L: Turns left and is now facing north.
  5. A: Advances to {9, 4}.
  6. L: Turns left again and is now facing west.

The robot’s final coordinates are {9, 4}, and it is facing west.

s/would/will/

Add punctuation:

This implies the decrease on W/S. Do we want to make that explicit? Or change “increase” to just “The coordinates change with every advance”

The rest of the text talks about the robot facing a direction, not pointing.

Just checked AP, CMOS. Both recommend not using punctuation. Another possibility is turning the vertical list into horizontal.

I’m not sure. Do you think it’s best if it isn’t mentioned? Current description reads “coordinates increasing to the north and east”, so I just kept it as is.

Fixed.

In my eyes, an explicit link is missing between the compass directions and the coordinates x,y. The assumptions, that x is the horizontal axis of any graph, that every map is north-oriented and that by this the x axis is identical to the west-east axis of such a map are a lot and not intuitive.

There is some kind of hidden explanation of this in the example, but it still requires to know what a compass looks like. Also the example does not repeat “x,y” for the names of the coordinates, one only sees the position of the numbers in the curly braces.

The same is true for the current instructions, and it doesn’t seem to be causing any issues so far. I’ll see if there’s a way to address this. But please keep in mind that I’m not trying to do a complete overhaul of the current instructions. Pretty much everything in the suggested update (with the exception of the example that goes into more details about the movement), also exists in the current description.

I think there is just some explanatory words missing, something like this:

The coordinates increase as we move north and east. The x part of the coordinates increases when moving north, and the y part increases going east.

This way there is a direct connection between compass directions and coordinate system, making all assumptions explicit.

Sure, that seems acceptable. Instructions updated.

I just noticed this. Story updated.

Brief explanation why CMOS does not recommend punctuation for this list. I’m quoting the book:

Vertical lists punctuated as a sentence: If the items in a vertical list complete a sentence begun in the introductory text, semicolons or commas may be used between the items, and a period should follow the final item.

This does not appear to be the case here. Punctuation would make sense in this case:

The task is to simulate the movement of a robot on a hypothetical infinite grid, where the robot can

* turn right,
* turn left, and
* advance forward one unit.

Another argument would be to capitalize each item and add period at the end, like so

The task is to simulate the movement of a robot on a hypothetical infinite grid, where the robot can perform three actions:

* Turn right.
* Turn left.
* Advance forward one unit.

That would be the recommendation, assuming the items are complete sentences. While they are indeed imperative sentences, they are not used as such in this context. Therefore, no punctuation is needed.