coding-exercises
coding-exercises copied to clipboard
Warehouse test - Part 3: Commands should be NE, SW etc.
Part three talks of issuing a command 'E N' which should be the same as issuing an east command then north, but this is what the code should already be doing, as the command lists are already space separated. The aim should be to support the commands NE, NW, SW & NE.
The user may also wish to support the inverted commands EN, WN, WS & WE. It's arguably overkill, but personally I've tried to make the command string parser as forgiving as possible, knowing full well you should never trust user input, and being flexible reduces possibility of user friction.
[Note: Not a Guardian employee or contractor. Doing tests as part of contract application process]
Part three states (emphasis mine):
We have expanded the robot's grid system to include diagonal tracks. Modify the robot's movement so that it can take advantage of the new diagonals. We don't want to change all the movement programmes though so don't change the syntax of the commands we send.
So for example if the robot starts in the south-west corner of the warehouse then issuing the command "E N" should move the robot to the same place as if it moved east once and north once but it should only move once.
Moving the robot once is not the same as moving the robot twice, even if it ends in the same position. Just like "N E S W" isn’t the same as not moving at all.
This can also lead to interesting discussions around maintenance, so I would be tempted to leave this as-is.