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


      1--- Day 11: Space Police ---
      2
      3On the way to Jupiter, you're pulled over by the Space Police.
      4
      5"Attention, unmarked spacecraft! You are in violation of Space Law! All spacecraft must have a
      6clearly visible registration identifier! You have 24 hours to comply or be sent to Space Jail!"
      7
      8Not wanting to be sent to Space Jail, you radio back to the Elves on Earth for help. Although it
      9takes almost three hours for their reply signal to reach you, they send instructions for how to
     10power up the emergency hull painting robot and even provide a small Intcode program (your puzzle
     11input) that will cause it to paint your ship appropriately.
     12
     13There's just one problem: you don't have an emergency hull painting robot.
     14
     15You'll need to build a new emergency hull painting robot. The robot needs to be able to move around
     16on the grid of square panels on the side of your ship, detect the color of its current panel, and
     17paint its current panel black or white. (All of the panels are currently black.)
     18
     19The Intcode program will serve as the brain of the robot. The program uses input instructions to
     20access the robot's camera: provide 0 if the robot is over a black panel or 1 if the robot is over a
     21white panel. Then, the program will output two values:
     22
     23
     24 - First, it will output a value indicating the color to paint the panel the robot is over: 0 means
     25to paint the panel black, and 1 means to paint the panel white.
     26
     27 - Second, it will output a value indicating the direction the robot should turn: 0 means it should
     28turn left 90 degrees, and 1 means it should turn right 90 degrees.
     29
     30
     31After the robot turns, it should always move forward exactly one panel. The robot starts facing
     32up.
     33
     34The robot will continue running for a while like this and halt when it is finished drawing.  Do not
     35restart the Intcode computer inside the robot during this process.
     36
     37For example, suppose the robot is about to start running.  Drawing black panels as ., white panels
     38as #, and the robot pointing the direction it is facing (< ^ > v), the initial state and region near
     39the robot looks like this:
     40
     41.....
     42.....
     43..^..
     44.....
     45.....
     46
     47The panel under the robot (not visible here because a ^ is shown instead) is also black, and so any
     48input instructions at this point should be provided 0. Suppose the robot eventually outputs 1 (paint
     49white) and then 0 (turn left). After taking these actions and moving forward one panel, the region
     50now looks like this:
     51
     52.....
     53.....
     54.<#..
     55.....
     56.....
     57
     58Input instructions should still be provided 0. Next, the robot might output 0 (paint black) and then
     590 (turn left):
     60
     61.....
     62.....
     63..#..
     64.v...
     65.....
     66
     67After more outputs (1,0, 1,0):
     68
     69.....
     70.....
     71..^..
     72.##..
     73.....
     74
     75The robot is now back where it started, but because it is now on a white panel, input instructions
     76should be provided 1.  After several more outputs (0,1, 1,0, 1,0), the area looks like this:
     77
     78.....
     79..<#.
     80...#.
     81.##..
     82.....
     83
     84Before you deploy the robot, you should probably have an estimate of the area it will cover:
     85specifically, you need to know the number of panels it paints at least once, regardless of color. In
     86the example above, the robot painted 6 panels at least once. (It painted its starting panel twice,
     87but that panel is still only counted once; it also never painted the panel it ended on.)
     88
     89Build a new emergency hull painting robot and run the Intcode program on it. How many panels does it
     90paint at least once?
     91
     92