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

part1 (2527B)


      1--- Day 12: Rain Risk ---
      2
      3Your ferry made decent progress toward the island, but the storm came in faster than anyone
      4expected. The ferry needs to take evasive actions!
      5
      6Unfortunately, the ship's navigation computer seems to be malfunctioning; rather than giving a route
      7directly to safety, it produced extremely circuitous instructions. When the captain uses the PA
      8system to ask if anyone can help, you quickly volunteer.
      9
     10The navigation instructions (your puzzle input) consists of a sequence of single-character
     11actions paired with integer input values. After staring at them for a few
     12minutes, you work out what they probably mean:
     13
     14
     15 - Action N means to move north by the given value.
     16 - Action S means to move south by the given value.
     17 - Action E means to move east by the given value.
     18 - Action W means to move west by the given value.
     19 - Action L means to turn left the given number of degrees.
     20 - Action R means to turn right the given number of degrees.
     21 - Action F means to move forward by the given value in the direction the
     22ship is currently facing.
     23
     24
     25The ship starts by facing east. Only the L and R actions change the direction the ship
     26is facing. (That is, if the ship is facing east and the next instruction is N10, the ship would move
     27north 10 units, but would still move east if the following action were F.)
     28
     29For example:
     30
     31F10
     32N3
     33F7
     34R90
     35F11
     36
     37These instructions would be handled as follows:
     38
     39
     40 - F10 would move the ship 10 units east (because the ship starts by facing east) to east
     4110, north 0.
     42 - N3 would move the ship 3 units north to east 10, north 3.
     43 - F7 would move the ship another 7 units east (because the ship is still facing east) to
     44east 17, north 3.
     45 - R90 would cause the ship to turn right by 90 degrees and face south; it remains at
     46east 17, north 3.
     47 - F11 would move the ship 11 units south to east 17, south 8.
     48
     49
     50At the end of these instructions, the ship's Manhattan distance (sum of the absolute values of its
     51east/west position and its north/south position) from its starting position is 17 + 8 =
     5225.
     53
     54Figure out where the navigation instructions lead. What is the Manhattan distance between
     55that location and the ship's starting position?
     56
     57