aoc-2019-c

Advent of Code 2019 Solutions in C
git clone https://git.sinitax.com/sinitax/aoc-2019-c
Log | Files | Refs | README | sfeed.txt

part1 (1871B)


      1--- Day 3: Crossed Wires ---
      2
      3The gravity assist was successful, and you're well on your way to the Venus refuelling station. 
      4During the rush back on Earth, the fuel management system wasn't completely installed, so that's
      5next on the priority list.
      6
      7Opening the front panel reveals a jumble of wires. Specifically, two wires are connected to a
      8central port and extend outward on a grid.  You trace the path each wire takes as it leaves the
      9central port, one wire per line of text (your puzzle input).
     10
     11The wires twist and turn, but the two wires occasionally cross paths. To fix the circuit, you need
     12to find the intersection point closest to the central port. Because the wires are on a grid, use the
     13Manhattan distance for this measurement. While the wires do technically cross right at the central
     14port where they both start, this point does not count, nor does a wire count as crossing with
     15itself.
     16
     17For example, if the first wire's path is R8,U5,L5,D3, then starting from the central port (o), it
     18goes right 8, up 5, left 5, and finally down 3:
     19
     20...........
     21...........
     22...........
     23....+----+.
     24....|....|.
     25....|....|.
     26....|....|.
     27.........|.
     28.o-------+.
     29...........
     30
     31Then, if the second wire's path is U7,R6,D4,L4, it goes up 7, right 6, down 4, and left 4:
     32
     33...........
     34.+-----+...
     35.|.....|...
     36.|..+--X-+.
     37.|..|..|.|.
     38.|.-X--+.|.
     39.|..|....|.
     40.|.......|.
     41.o-------+.
     42...........
     43
     44These wires cross at two locations (marked X), but the lower-left one is closer to the central port:
     45its distance is 3 + 3 = 6.
     46
     47Here are a few more examples:
     48
     49
     50 - R75,D30,R83,U83,L12,D49,R71,U7,L72
     51U62,R66,U55,R34,D71,R55,D58,R83 = distance 159
     52
     53 - R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51
     54U98,R91,D20,R16,D67,R40,U7,R15,U6,R7 = distance 135
     55
     56
     57What is the Manhattan distance from the central port to the closest intersection?
     58
     59