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


      1--- Part Two ---
      2
      3Now for the tricky part: notifying all the other robots about the solar flare.  The vacuum robot can
      4do this automatically if it gets into range of a robot. However, you can't see the other robots on
      5the camera, so you need to be thorough instead: you need to make the vacuum robot visit every part
      6of the scaffold at least once.
      7
      8The vacuum robot normally wanders randomly, but there isn't time for that today.  Instead, you can
      9override its movement logic with new rules.
     10
     11Force the vacuum robot to wake up by changing the value in your ASCII program at address 0 from 1 to
     122. When you do this, you will be automatically prompted for the new movement rules that the vacuum
     13robot should use. The ASCII program will use input instructions to receive them, but they need to be
     14provided as ASCII code; end each line of logic with a single newline, ASCII code 10.
     15
     16First, you will be prompted for the main movement routine.  The main routine may only call the
     17movement functions: A, B, or C. Supply the movement functions to use as ASCII text, separating them
     18with commas (,, ASCII code 44), and ending the list with a newline (ASCII code 10). For example, to
     19call A twice, then alternate between B and C three times, provide the string A,A,B,C,B,C,B,C and
     20then a newline.
     21
     22Then, you will be prompted for each movement function. Movement functions may use L to turn
     23left, R to turn right, or a number to move forward that many units.  Movement functions may not call
     24other movement functions.  Again, separate the actions with commas and end the list with a newline. 
     25For example, to move forward 10 units, turn left, move forward 8 units, turn right, and finally move
     26forward 6 units, provide the string 10,L,8,R,6 and then a newline.
     27
     28Finally, you will be asked whether you want to see a continuous video feed; provide either y or n
     29and a newline.  Enabling the continuous video feed can help you see what's going on, but it also
     30requires a significant amount of processing power, and may even cause your Intcode computer to
     31overheat.
     32
     33Due to the limited amount of memory in the vacuum robot, the ASCII definitions of the main routine
     34and the movement functions may each contain at most 20 characters, not counting the newline.
     35
     36For example, consider the following camera feed:
     37
     38#######...#####
     39#.....#...#...#
     40#.....#...#...#
     41......#...#...#
     42......#...###.#
     43......#.....#.#
     44^########...#.#
     45......#.#...#.#
     46......#########
     47........#...#..
     48....#########..
     49....#...#......
     50....#...#......
     51....#...#......
     52....#####......
     53
     54In order for the vacuum robot to visit every part of the scaffold at least once, one path it could
     55take is:
     56
     57R,8,R,8,R,4,R,4,R,8,L,6,L,2,R,4,R,4,R,8,R,8,R,8,L,6,L,2
     58Without the memory limit, you could just supply this whole string to function A and have the main
     59routine call A once.  However, you'll need to split it into smaller parts.
     60
     61One approach is:
     62
     63
     64 - Main routine: A,B,C,B,A,C(ASCII input: 65, 44, 66, 44, 67, 44, 66, 44, 65, 44, 67, 10)
     65
     66 - Function A:   R,8,R,8(ASCII input: 82, 44, 56, 44, 82, 44, 56, 10)
     67
     68 - Function B:   R,4,R,4,R,8(ASCII input: 82, 44, 52, 44, 82, 44, 52, 44, 82, 44, 56, 10)
     69
     70 - Function C:   L,6,L,2(ASCII input: 76, 44, 54, 44, 76, 44, 50, 10)
     71
     72
     73Visually, this would break the desired path into the following parts:
     74
     75A,        B,            C,        B,            A,        C
     76R,8,R,8,  R,4,R,4,R,8,  L,6,L,2,  R,4,R,4,R,8,  R,8,R,8,  L,6,L,2
     77
     78CCCCCCA...BBBBB
     79C.....A...B...B
     80C.....A...B...B
     81......A...B...B
     82......A...CCC.B
     83......A.....C.B
     84^AAAAAAAA...C.B
     85......A.A...C.B
     86......AAAAAA#AB
     87........A...C..
     88....BBBB#BBBB..
     89....B...A......
     90....B...A......
     91....B...A......
     92....BBBBA......
     93
     94Of course, the scaffolding outside your ship is much more complex.
     95
     96As the vacuum robot finds other robots and notifies them of the impending solar flare, it also can't
     97help but leave them squeaky clean, collecting any space dust it finds. Once it finishes the
     98programmed set of movements, assuming it hasn't drifted off into space, the cleaning robot will
     99return to its docking station and report the amount of space dust it collected as a large, non-ASCII
    100value in a single output instruction.
    101
    102After visiting every part of the scaffold at least once, how much dust does the vacuum robot report
    103it has collected?
    104
    105