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 (3335B)


      1--- Day 17: Set and Forget ---
      2
      3An early warning system detects an incoming solar flare and automatically activates the ship's
      4electromagnetic shield. Unfortunately, this has cut off the Wi-Fi for many small robots that,
      5unaware of the impending danger, are now trapped on exterior scaffolding on the unsafe side of the
      6shield. To rescue them, you'll have to act quickly!
      7
      8The only tools at your disposal are some wired cameras and a small vacuum robot currently asleep at
      9its charging station. The video quality is poor, but the vacuum robot has a needlessly bright LED
     10that makes it easy to spot no matter where it is.
     11
     12An Intcode program, the Aft Scaffolding Control and Information Interface (ASCII, your puzzle
     13input), provides access to the cameras and the vacuum robot.  Currently, because the vacuum robot is
     14asleep, you can only access the cameras.
     15
     16Running the ASCII program on your Intcode computer will provide the current view of the scaffolds. 
     17This is output, purely coincidentally, as ASCII code: 35 means #, 46 means ., 10 starts a new line
     18of output below the current one, and so on. (Within a line, characters are drawn left-to-right.)
     19
     20In the camera output, # represents a scaffold and . represents open space. The vacuum robot is
     21visible as ^, v, <, or > depending on whether it is facing up, down, left, or right respectively.
     22When drawn like this, the vacuum robot is always on a scaffold; if the vacuum robot ever walks off
     23of a scaffold and begins tumbling through space uncontrollably, it will instead be visible as X.
     24
     25In general, the scaffold forms a path, but it sometimes loops back onto itself.  For example,
     26suppose you can see the following view from the cameras:
     27
     28..#..........
     29..#..........
     30#######...###
     31#.#...#...#.#
     32#############
     33..#...#...#..
     34..#####...^..
     35
     36Here, the vacuum robot, ^ is facing up and sitting at one end of the scaffold near the bottom-right
     37of the image. The scaffold continues up, loops across itself several times, and ends at the top-left
     38of the image.
     39
     40The first step is to calibrate the cameras by getting the alignment parameters of some well-defined
     41points.  Locate all scaffold intersections; for each, its alignment parameter is the distance
     42between its left edge and the left edge of the view multiplied by the distance between its top edge
     43and the top edge of the view.  Here, the intersections from the above image are marked O:
     44
     45..#..........
     46..#..........
     47##O####...###
     48#.#...#...#.#
     49##O###O###O##
     50..#...#...#..
     51..#####...^..
     52
     53For these intersections:
     54
     55
     56 - The top-left intersection is 2 units from the left of the image and 2 units from the top of the
     57image, so its alignment parameter is 2 * 2 = 4.
     58
     59 - The bottom-left intersection is 2 units from the left and 4 units from the top, so its alignment
     60parameter is 2 * 4 = 8.
     61
     62 - The bottom-middle intersection is 6 from the left and 4 from the top, so its alignment parameter
     63is 24.
     64
     65 - The bottom-right intersection's alignment parameter is 40.
     66
     67
     68To calibrate the cameras, you need the sum of the alignment parameters.  In the above example, this
     69is 76.
     70
     71Run your ASCII program. What is the sum of the alignment parameters for the scaffold intersections?
     72
     73