part1 (3255B)
1--- Day 15: Oxygen System --- 2 3Out here in deep space, many things can go wrong. Fortunately, many of those things have indicator 4lights. Unfortunately, one of those lights is lit: the oxygen system for part of the ship has 5failed! 6 7According to the readouts, the oxygen system must have failed days ago after a rupture in oxygen 8tank two; that section of the ship was automatically sealed once oxygen levels went dangerously low. 9A single remotely-operated [1m[97mrepair droid[0m is your only option for fixing the oxygen system. 10 11The Elves' care package included an Intcode program (your puzzle input) that you can use to remotely 12control the repair droid. By running that program, you can direct the repair droid to the oxygen 13system and fix the problem. 14 15The remote control program executes the following steps in a loop forever: 16 17 18 - Accept a [1m[97mmovement command[0m via an input instruction. 19 20 - Send the movement command to the repair droid. 21 22 - Wait for the repair droid to finish the movement operation. 23 24 - Report on the [1m[97mstatus[0m of the repair droid via an output instruction. 25 26 27Only four [1m[97mmovement commands[0m are understood: north (1), south (2), west (3), and east (4). Any other 28command is invalid. The movements differ in direction, but not in distance: in a long enough 29east-west hallway, a series of commands like 4,4,4,4,3,3,3,3 would leave the repair droid back where 30it started. 31 32The repair droid can reply with any of the following [1m[97mstatus[0m codes: 33 34 35 - 0: The repair droid hit a wall. Its position has not changed. 36 37 - 1: The repair droid has moved one step in the requested direction. 38 39 - 2: The repair droid has moved one step in the requested direction; its new position is the 40location of the oxygen system. 41 42 43You don't know anything about the area around the repair droid, but you can figure it out by 44watching the status codes. 45 46For example, we can draw the area using D for the droid, # for walls, . for locations the droid can 47traverse, and empty space for unexplored locations. Then, the initial state looks like this: 48 49 50 51 D 52 53 54 55To make the droid go north, send it 1. If it replies with 0, you know that location is a wall and 56that the droid didn't move: 57 58 59 # 60 D 61 62 63 64To move east, send 4; a reply of 1 means the movement was successful: 65 66 67 # 68 .D 69 70 71 72Then, perhaps attempts to move north (1), south (2), and east (4) are all met with replies of 0: 73 74 75 ## 76 .D# 77 # 78 79 80Now, you know the repair droid is in a dead end. Backtrack with 3 (which you already know will get a 81reply of 1 because you already know that location is open): 82 83 84 ## 85 D.# 86 # 87 88 89Then, perhaps west (3) gets a reply of 0, south (2) gets a reply of 1, south again (2) gets a reply 90of 0, and then west (3) gets a reply of 2: 91 92 93 ## 94 #..# 95 D.# 96 # 97 98Now, because of the reply of 2, you know you've found the [1m[97moxygen system[0m! In this example, it was 99only [1m[97m2[0m moves away from the repair droid's starting position. 100 101[1m[97mWhat is the fewest number of movement commands[0m required to move the repair droid from its starting 102position to the location of the oxygen system? 103 104