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