Skip to content

Instantly share code, notes, and snippets.

@ben-gy
Created February 10, 2016 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben-gy/09d9186ee0b7dba28dec to your computer and use it in GitHub Desktop.
Save ben-gy/09d9186ee0b7dba28dec to your computer and use it in GitHub Desktop.
Captain Harrison is busy exploring Nifty's Loch. Unfortunately - he keeps getting lost. You decide to help him by building a positioning system that can be installed on his ship (The SS Reckoning).
Luckily, Nifty's Loch is a a perfect square, 10 units high and 10 units wide. With the docks positioned at (0,0).
As the ship moves or changes direction, it will send messages to your positioning system. These relate to the ship moving forwards or changing direction. For example:
F 4 - This will move the ship forward four units, not changing the direction the ship is pointing in. B 2 - This will move the ship backwards two units, not changing the direction the ship is pointing in. L 2 - This will rotate the ship 90 degrees left twice. L 2 then makes the ship point in the opposite direction, while L 4 does a complete 360 and point in the same direction. 'R 3' - This will turn the ship right 90 degrees, 3 times.
When the program receives the REPORT command, it should give it's current position, as well as the compass bearing. If the SS Reckoning was at (2,3) while facing east, it will return the following:
2 3 E
If the SS Reckoning runs into the side of the Loch, it should not be allowed to travel any further in that direction.
Being the stickler for good software engineering that he is, Captain Harrison will expect sound OOP principles, as well tests covering your application. The program can accept input however you choose.`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment