part1 (3335B)
1--- Day 17: Set and Forget --- 2 3An early warning system detects an incoming solar flare and automatically activates the ship's 4electromagnetic shield. Unfortunately, this has cut off the Wi-Fi for many small robots that, 5unaware of the impending danger, are now trapped on exterior scaffolding on the unsafe side of the 6shield. To rescue them, you'll have to act quickly! 7 8The only tools at your disposal are some wired cameras and a small vacuum robot currently asleep at 9its charging station. The video quality is poor, but the vacuum robot has a needlessly bright LED 10that makes it easy to spot no matter where it is. 11 12An Intcode program, the [1m[97mAft Scaffolding Control and Information Interface[0m (ASCII, your puzzle 13input), provides access to the cameras and the vacuum robot. Currently, because the vacuum robot is 14asleep, you can only access the cameras. 15 16Running the ASCII program on your Intcode computer will provide the current view of the scaffolds. 17This is output, purely coincidentally, as ASCII code: 35 means #, 46 means ., 10 starts a new line 18of output below the current one, and so on. (Within a line, characters are drawn left-to-right.) 19 20In the camera output, # represents a scaffold and . represents open space. The vacuum robot is 21visible as ^, v, <, or > depending on whether it is facing up, down, left, or right respectively. 22When drawn like this, the vacuum robot is [1m[97malways on a scaffold[0m; if the vacuum robot ever walks off 23of a scaffold and begins [1m[97mtumbling through space uncontrollably[0m, it will instead be visible as X. 24 25In general, the scaffold forms a path, but it sometimes loops back onto itself. For example, 26suppose you can see the following view from the cameras: 27 28..#.......... 29..#.......... 30#######...### 31#.#...#...#.# 32############# 33..#...#...#.. 34..#####...^.. 35 36Here, the vacuum robot, ^ is facing up and sitting at one end of the scaffold near the bottom-right 37of the image. The scaffold continues up, loops across itself several times, and ends at the top-left 38of the image. 39 40The first step is to calibrate the cameras by getting the [1m[97malignment parameters[0m of some well-defined 41points. Locate all [1m[97mscaffold intersections[0m; for each, its alignment parameter is the distance 42between its left edge and the left edge of the view multiplied by the distance between its top edge 43and the top edge of the view. Here, the intersections from the above image are marked O: 44 45..#.......... 46..#.......... 47##O####...### 48#.#...#...#.# 49##O###O###O## 50..#...#...#.. 51..#####...^.. 52 53For these intersections: 54 55 56 - The top-left intersection is 2 units from the left of the image and 2 units from the top of the 57image, so its alignment parameter is 2 * 2 = [1m[97m4[0m. 58 59 - The bottom-left intersection is 2 units from the left and 4 units from the top, so its alignment 60parameter is 2 * 4 = [1m[97m8[0m. 61 62 - The bottom-middle intersection is 6 from the left and 4 from the top, so its alignment parameter 63is [1m[97m24[0m. 64 65 - The bottom-right intersection's alignment parameter is [1m[97m40[0m. 66 67 68To calibrate the cameras, you need the [1m[97msum of the alignment parameters[0m. In the above example, this 69is [1m[97m76[0m. 70 71Run your ASCII program. [1m[97mWhat is the sum of the alignment parameters[0m for the scaffold intersections? 72 73