F -- move Forward by the given value in the direction the ship is facing
The ship starts out facing East, at a location we'll call (0 East, 0 North).
For example, consider these steps:
F10
N3
F7
R90
F11
These steps would have these results:
F10 moves the ship 10 units East (because the ship starts out facing East) to location (10 East, 0 North)
N3 moves the ship 3 units North to location (10 East, 3 North)
F7 moves another 7 units East (the ship is still facing East) to location (17 East, 3 North)
R90 turns the ship so it is facing South
F11 moves 11 units South to location (17 East, 8 South)
At the end of these steps, the ship has moved a "Manhattan Distance" of 25 units.
Manhattan distance is calculated along the sides of a grid,
never moving diagonally, so it is the sum of the absolute values of
its east/west position and its north/south position.
Problem Statement
Perform a series of steps.
Find the total Manhattan Distance moved.
In the example above, the result is 25.
You discover that you have misinterpreted the instructions.
In fact, most of the actions indicate how a "waypoint"
should move, not the ship itself.
N -- move the waypoint North by the given value
S -- move the waypoint South by the given value
E -- move the waypoint East by the given value
W -- move the waypoint West by the given value
L -- rotate the waypoint Left (counter-clockwise) around the ship
the given number of degrees
R -- rotate the waypoint Right (clockwise) around the ship
the given number of degrees
F -- move Forward to the waypoint a number of times equal to the given value
The waypoint starts 10 units east and 1 unit north relative to the ship.
The waypoint is relative to the ship; that is, if the ship moves, the waypoint moves with it.
For example, consider these steps:
F10
N3
F7
R90
F11
These steps would have these results:
F10 moves the ship to the waypoint 10 times. The waypoint is at (10 East, 1 North), so the ship moves to location (100 East, 10 North). The waypoint stays at (10 East, 1 North) relative to the ship.
N3 moves the waypoint 3 units North to (10 East, 4 North) relative to the ship.
F7 moves the ship to the waypoint 7 times. The waypoint is at (10 East, 4 North), so the ship moves to location (170 East, 38 North). The waypoint stays at (10 East, 4 North) relative to the ship.
R90 rotates the waypoint 90 degrees clockwise around the ship, to location (4 East, 10 South) relative to the ship. The ship remains at (170 East, 38 North).
F11 moves the ship to the waypoint 11 times. The waypoint is at (4 East, 10 South), so the ship moves to location (214 East, 72 South). The waypoint stays at (4 East, 10 South) relative to the ship.
At the end of these steps, the ship has moved a "Manhattan Distance" of 214 + 72 = 286 units.