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 [1m[97mjump[0m over the holes in the hull - a 13[1m[97mspringdroid[0m. 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 [1m[97mspringscript[0m. 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 [1m[97m15[0m springscript instructions. 21 22The springdroid will move forward automatically, constantly thinking about [1m[97mwhether to jump[0m. 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 [1m[97mtemporary value[0m register, and J, the [1m[97mjump[0m register. If the jump register is 27[1m[97mtrue[0m at the end of the springscript program, the springdroid will try to jump. Both of these 28registers start with the value [1m[97mfalse[0m. 29 30Springdroids have a sensor that can detect [1m[97mwhether there is ground[0m at various distances in the 31direction it is facing; these values are provided in [1m[97mread-only registers[0m. 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 34[1m[97mtrue[0m; if there is a hole, the register will be [1m[97mfalse[0m. 35 36There are only [1m[97mthree instructions[0m available in springscript: 37 38 39 - AND X Y sets Y to [1m[97mtrue[0m if both X and Y are [1m[97mtrue[0m; otherwise, it sets Y to [1m[97mfalse[0m. 40 41 - OR X Y sets Y to [1m[97mtrue[0m if at least one of X or Y is [1m[97mtrue[0m; otherwise, it sets Y to 42[1m[97mfalse[0m. 43 44 - NOT X Y sets Y to [1m[97mtrue[0m if X is [1m[97mfalse[0m; otherwise, it sets Y to [1m[97mfalse[0m. 45 46 47In all three instructions, the second argument (Y) needs to be a [1m[97mwritable register[0m (either T or J). 48The first argument (X) can be [1m[97many register[0m (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). 65[1m[97mWhen you have finished entering your program[0m, provide the command WALK followed by a newline to 66instruct the springdroid to begin surveying the hull. 67 68If the springdroid [1m[97mfalls into space[0m, 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 [1m[97mtrue[0m 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[1m[97m@[0m................ 80#####.########### 81 82................. 83................. 84.[1m[97m@[0m............... 85#####.########### 86 87................. 88..[1m[97m@[0m.............. 89................. 90#####.########### 91 92...[1m[97m@[0m............. 93................. 94................. 95#####.########### 96 97................. 98....[1m[97m@[0m............ 99................. 100#####.########### 101 102................. 103................. 104.....[1m[97m@[0m........... 105#####.########### 106 107................. 108................. 109................. 110#####[1m[97m@[0m########### 111 112However, if the springdroid successfully makes it across, it will use an output instruction to 113indicate the [1m[97mamount of damage to the hull[0m 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. 116[1m[97mWhat amount of hull damage does it report?[0m 117 118 119