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


      1--- Day 21: Springdroid Adventure ---
      2
      3You lift off from Pluto and start flying in the direction of Santa.
      4
      5While experimenting further with the tractor beam, you accidentally pull an asteroid directly into
      6your ship!  It deals significant damage to your hull and causes your ship to begin tumbling
      7violently.
      8
      9You can send a droid out to investigate, but the tumbling is causing enough artificial gravity that
     10one wrong step could send the droid through a hole in the hull and flying out into space.
     11
     12The clear choice for this mission is a droid that can jump over the holes in the hull - a
     13springdroid.
     14
     15You can use an Intcode program (your puzzle input) running on an ASCII-capable computer to program
     16the springdroid. However, springdroids don't run Intcode; instead, they run a simplified assembly
     17language called springscript.
     18
     19While a springdroid is certainly capable of navigating the artificial gravity and giant holes, it
     20has one downside: it can only remember at most 15 springscript instructions.
     21
     22The springdroid will move forward automatically, constantly thinking about whether to jump.  The
     23springscript program defines the logic for this decision.
     24
     25Springscript programs only use Boolean values, not numbers or strings.  Two registers are available:
     26T, the temporary value register, and J, the jump register.  If the jump register is
     27true at the end of the springscript program, the springdroid will try to jump. Both of these
     28registers start with the value false.
     29
     30Springdroids have a sensor that can detect whether there is ground at various distances in the
     31direction it is facing; these values are provided in read-only registers.  Your springdroid can
     32detect ground at four distances: one tile away (A), two tiles away (B), three tiles away (C), and
     33four tiles away (D). If there is ground at the given distance, the register will be
     34true; if there is a hole, the register will be false.
     35
     36There are only three instructions available in springscript:
     37
     38
     39 - AND X Y sets Y to true if both X and Y are true; otherwise, it sets Y to false.
     40
     41 - OR X Y sets Y to true if at least one of X or Y is true; otherwise, it sets Y to
     42false.
     43
     44 - NOT X Y sets Y to true if X is false; otherwise, it sets Y to false.
     45
     46
     47In all three instructions, the second argument (Y) needs to be a writable register (either T or J).
     48The first argument (X) can be any register (including A, B, C, or D).
     49
     50For example, the one-instruction program NOT A J means "if the tile immediately in front of me is
     51not ground, jump".
     52
     53Or, here is a program that jumps if a three-tile-wide hole (with ground on the other side of the
     54hole) is detected:
     55
     56NOT A J
     57NOT B T
     58AND T J
     59NOT C T
     60AND T J
     61AND D J
     62
     63The Intcode program expects ASCII inputs and outputs.  It will begin by displaying a prompt; then,
     64input the desired instructions one per line. End each line with a newline (ASCII code 10).
     65When you have finished entering your program, provide the command WALK followed by a newline to
     66instruct the springdroid to begin surveying the hull.
     67
     68If the springdroid falls into space, an ASCII rendering of the last moments of its life will be
     69produced.  In these, @ is the springdroid, # is hull, and . is empty space.  For example, suppose
     70you program the springdroid like this:
     71NOT D J
     72WALK
     73
     74This one-instruction program sets J to true if and only if there is no ground four tiles away.  In
     75other words, it attempts to jump into any hole it finds:
     76
     77.................
     78.................
     79@................
     80#####.###########
     81
     82.................
     83.................
     84.@...............
     85#####.###########
     86
     87.................
     88..@..............
     89.................
     90#####.###########
     91
     92...@.............
     93.................
     94.................
     95#####.###########
     96
     97.................
     98....@............
     99.................
    100#####.###########
    101
    102.................
    103.................
    104.....@...........
    105#####.###########
    106
    107.................
    108.................
    109.................
    110#####@###########
    111
    112However, if the springdroid successfully makes it across, it will use an output instruction to
    113indicate the amount of damage to the hull as a single giant integer outside the normal ASCII range.
    114
    115Program the springdroid with logic that allows it to survey the hull without falling into space. 
    116What amount of hull damage does it report?
    117
    118
    119