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

part2 (1604B)


      1--- Part Two ---
      2
      3It turns out that this circuit is very timing-sensitive; you actually need to minimize the signal
      4delay.
      5
      6To do this, calculate the number of steps each wire takes to reach each intersection; choose the
      7intersection where the sum of both wires' steps is lowest. If a wire visits a position on the grid
      8multiple times, use the steps value from the first time it visits that position when calculating the
      9total value of a specific intersection.
     10
     11The number of steps a wire takes is the total number of grid squares the wire has entered to get to
     12that location, including the intersection being considered. Again consider the example from above:
     13
     14...........
     15.+-----+...
     16.|.....|...
     17.|..+--X-+.
     18.|..|..|.|.
     19.|.-X--+.|.
     20.|..|....|.
     21.|.......|.
     22.o-------+.
     23...........
     24
     25In the above example, the intersection closest to the central port is reached after 8+5+5+2 =
     2620 steps by the first wire and 7+6+4+3 = 20 steps by the second wire for a total of 20+20 =
     2740 steps.
     28
     29However, the top-right intersection is better: the first wire takes only 8+5+2 = 15 and the second
     30wire takes only 7+6+2 = 15, a total of 15+15 = 30 steps.
     31
     32Here are the best steps for the extra examples from above:
     33
     34
     35 - R75,D30,R83,U83,L12,D49,R71,U7,L72
     36U62,R66,U55,R34,D71,R55,D58,R83 = 610 steps
     37
     38 - R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51
     39U98,R91,D20,R16,D67,R40,U7,R15,U6,R7 = 410 steps
     40
     41
     42What is the fewest combined steps the wires must take to reach an intersection?
     43
     44