aboutsummaryrefslogtreecommitdiffstats
path: root/src/17/part1
blob: 9a3bba867a3e67d0772e745f7c1dbcdf895b675b (plain) (blame)
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
--- Day 17: Set and Forget ---

An early warning system detects an incoming solar flare and automatically activates the ship's
electromagnetic shield. Unfortunately, this has cut off the Wi-Fi for many small robots that,
unaware of the impending danger, are now trapped on exterior scaffolding on the unsafe side of the
shield. To rescue them, you'll have to act quickly!

The only tools at your disposal are some wired cameras and a small vacuum robot currently asleep at
its charging station. The video quality is poor, but the vacuum robot has a needlessly bright LED
that makes it easy to spot no matter where it is.

An Intcode program, the Aft Scaffolding Control and Information Interface (ASCII, your puzzle
input), provides access to the cameras and the vacuum robot.  Currently, because the vacuum robot is
asleep, you can only access the cameras.

Running the ASCII program on your Intcode computer will provide the current view of the scaffolds. 
This is output, purely coincidentally, as ASCII code: 35 means #, 46 means ., 10 starts a new line
of output below the current one, and so on. (Within a line, characters are drawn left-to-right.)

In the camera output, # represents a scaffold and . represents open space. The vacuum robot is
visible as ^, v, <, or > depending on whether it is facing up, down, left, or right respectively.
When drawn like this, the vacuum robot is always on a scaffold; if the vacuum robot ever walks off
of a scaffold and begins tumbling through space uncontrollably, it will instead be visible as X.

In general, the scaffold forms a path, but it sometimes loops back onto itself.  For example,
suppose you can see the following view from the cameras:

..#..........
..#..........
#######...###
#.#...#...#.#
#############
..#...#...#..
..#####...^..

Here, the vacuum robot, ^ is facing up and sitting at one end of the scaffold near the bottom-right
of the image. The scaffold continues up, loops across itself several times, and ends at the top-left
of the image.

The first step is to calibrate the cameras by getting the alignment parameters of some well-defined
points.  Locate all scaffold intersections; for each, its alignment parameter is the distance
between its left edge and the left edge of the view multiplied by the distance between its top edge
and the top edge of the view.  Here, the intersections from the above image are marked O:

..#..........
..#..........
##O####...###
#.#...#...#.#
##O###O###O##
..#...#...#..
..#####...^..

For these intersections:


 - The top-left intersection is 2 units from the left of the image and 2 units from the top of the
image, so its alignment parameter is 2 * 2 = 4.

 - The bottom-left intersection is 2 units from the left and 4 units from the top, so its alignment
parameter is 2 * 4 = 8.

 - The bottom-middle intersection is 6 from the left and 4 from the top, so its alignment parameter
is 24.

 - The bottom-right intersection's alignment parameter is 40.


To calibrate the cameras, you need the sum of the alignment parameters.  In the above example, this
is 76.

Run your ASCII program. What is the sum of the alignment parameters for the scaffold intersections?