aoc-2020-zig

Advent of Code 2020 Solutions in Zig
git clone https://git.sinitax.com/sinitax/aoc-2020-zig
Log | Files | Refs | README | sfeed.txt

part2 (2594B)


      1--- Part Two ---
      2
      3Before you can give the destination to the captain, you realize that the actual action meanings were
      4printed on the back of the instructions the whole time.
      5
      6Almost all of the actions indicate how to move a waypoint which is relative to the
      7ship's position:
      8
      9
     10 - Action N means to move the waypoint north by the given value.
     11 - Action S means to move the waypoint south by the given value.
     12 - Action E means to move the waypoint east by the given value.
     13 - Action W means to move the waypoint west by the given value.
     14 - Action L means to rotate the waypoint around the ship left
     15(counter-clockwise) the given number of degrees.
     16 - Action R means to rotate the waypoint around the ship right
     17(clockwise) the given number of degrees.
     18 - Action F means to move forward to the waypoint a number of times equal
     19to the given value.
     20
     21
     22The waypoint starts 10 units east and 1 unit north relative to the ship. The waypoint
     23is relative to the ship; that is, if the ship moves, the waypoint moves with it.
     24
     25For example, using the same instructions as above:
     26
     27
     28 - F10 moves the ship to the waypoint 10 times (a total of 100 units east and 10 units
     29north), leaving the ship at east 100, north 10. The waypoint stays 10 units east
     30and 1 unit north of the ship.
     31 - N3 moves the waypoint 3 units north to 10 units east and 4 units north of the ship.
     32The ship remains at east 100, north 10.
     33 - F7 moves the ship to the waypoint 7 times (a total of 70 units east and 28 units
     34north), leaving the ship at east 170, north 38. The waypoint stays 10 units east
     35and 4 units north of the ship.
     36 - R90 rotates the waypoint around the ship clockwise 90 degrees, moving it to 4 units east
     37and 10 units south of the ship. The ship remains at east 170, north 38.
     38 - F11 moves the ship to the waypoint 11 times (a total of 44 units east and 110 units
     39south), leaving the ship at east 214, south 72. The waypoint stays 4 units east and
     4010 units south of the ship.
     41
     42
     43After these operations, the ship's Manhattan distance from its starting position is 214 + 72 =
     44286.
     45
     46Figure out where the navigation instructions actually lead. What is the Manhattan distance
     47between that location and the ship's starting position?
     48
     49