aoc-2019-c

git clone https://git.sinitax.com/sinitax/aoc-2019-c
Log | Files | Refs | README | sfeed.txt

commit 275a3d01c70d70487e4307e8735106d895803cba
parent 57ccf30bbe25ea907a6c4136ceb39ad3f5fa589d
Author: Louis Burda <quent.burda@gmail.com>
Date:   Fri,  7 Apr 2023 16:26:45 -0400

Use vtty colored text for all days

Diffstat:
M.gitmodules | 3---
M01/main.c | 4++--
M01/part1 | 13+++++++------
M01/part2 | 16+++++++++-------
M02/part1 | 52+++++++++++++++++++++++++++-------------------------
M02/part2 | 47+++++++++++++++++++++++------------------------
M03/part1 | 18+++++++++---------
M03/part2 | 22+++++++++++-----------
M04/part1 | 11+++++------
M04/part2 | 10++++------
M05/part1 | 69++++++++++++++++++++++++++++++++-------------------------------------
M05/part2 | 51+++++++++++++++++++++++++--------------------------
M06/part1 | 13++++++-------
M06/part2 | 27+++++++++++++--------------
M07/part1 | 26++++++++++++--------------
M07/part2 | 31+++++++++++++++----------------
M08/part1 | 10+++++-----
M08/part2 | 25+++++++++++--------------
M09/part1 | 31+++++++++++++++----------------
M09/part2 | 9++++-----
M10/part1 | 25++++++++++++-------------
M10/part2 | 50+++++++++++++++++++++++++-------------------------
M11/part1 | 41++++++++++++++++++-----------------------
M11/part2 | 13++++++-------
M12/part1 | 54+++++++++++++++++++++++++-----------------------------
M12/part2 | 13++++++-------
M13/part1 | 31+++++++++++++++----------------
M13/part2 | 9++++-----
M14/part1 | 27++++++++++++++-------------
M14/part2 | 121++++++-------------------------------------------------------------------------
M15/part1 | 16++++++++--------
M15/part2 | 10+++++-----
M16/part1 | 14+++++++-------
M16/part2 | 18+++++++++---------
M17/part1 | 24++++++++++++------------
M17/part2 | 38+++++++++++++++++++-------------------
M18/part1 | 14+++++++-------
M18/part2 | 22+++++++++++-----------
M19/part1 | 18+++++++++---------
M19/part2 | 16++++++++--------
M20/part1 | 8++++----
M20/part2 | 14+++++++-------
M21/part1 | 65+++++++++++++++++++++++++++++++++--------------------------------
M21/part2 | 22+++++++++++-----------
M22/part1 | 16++++++++--------
M22/part2 | 14+++++++-------
M23/part1 | 28++++++++++++++--------------
M23/part2 | 14+++++++-------
M24/part1 | 20++++++++++----------
M24/part2 | 21+++++++++++----------
M25/main.c | 6++++++
M25/part1 | 12++++++------
M25/part2 | 2+-
Mcommon/aoc.h | 3++-
Mcommon/main.c | 3++-
Dlib/libpq | 1-
56 files changed, 592 insertions(+), 719 deletions(-)

diff --git a/.gitmodules b/.gitmodules @@ -13,6 +13,3 @@ [submodule "lib/liblist"] path = lib/liblist url = git@sinitax.com:snx/liblist -[submodule "lib/libpq"] - path = lib/libpq - url = git@sinitax.com:snx/libpq diff --git a/01/main.c b/01/main.c @@ -10,8 +10,8 @@ void part1(void) { - const char *pos, *end; char buf[256]; + const char *pos, *end; int64_t fuel, ans; pos = aoc.input; @@ -30,8 +30,8 @@ part1(void) void part2(void) { - const char *pos, *end; char buf[256]; + const char *pos, *end; int64_t fuel, ans; pos = aoc.input; diff --git a/01/part1 b/01/part1 @@ -2,8 +2,7 @@ Santa has become stranded at the edge of the Solar System while delivering presents to other planets! To accurately calculate his position in space, safely align his warp drive, and return to -Earth in time to save Christmas, he needs you to bring him measurements from fifty -stars. +Earth in time to save Christmas, he needs you to bring him measurements from fifty stars. Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants @@ -14,16 +13,18 @@ The Elves quickly load you into a spacecraft and prepare to launch. At the first Go / No Go poll, every Elf is Go until the Fuel Counter-Upper. They haven't determined the amount of fuel required yet. -Fuel required to launch a given module is based on its mass. -Specifically, to find the fuel required for a module, take its mass, divide by three, round down, -and subtract 2. +Fuel required to launch a given module is based on its mass. Specifically, to find the fuel +required for a module, take its mass, divide by three, round down, and subtract 2. For example: - For a mass of 12, divide by 3 and round down to get 4, then subtract 2 to get 2. + - For a mass of 14, dividing by 3 and rounding down still yields 4, so the fuel required is also 2. + - For a mass of 1969, the fuel required is 654. + - For a mass of 100756, the fuel required is 33583. @@ -31,6 +32,6 @@ The Fuel Counter-Upper needs to know the total fuel requirement. To find it, in the fuel needed for the mass of each module (your puzzle input), then add together all the fuel values. -What is the sum of the fuel requirements for all of the modules on your spacecraft? +What is the sum of the fuel requirements for all of the modules on your spacecraft? diff --git a/01/part2 b/01/part2 @@ -4,10 +4,10 @@ During the second Go / No Go poll, the Elf in charge of the Rocket Equation Doub launch sequence. Apparently, you forgot to include additional fuel for the fuel you just added. Fuel itself requires fuel just like a module - take its mass, divide by three, round down, and -subtract 2. However, that fuel also requires fuel, and that fuel requires -fuel, and so on. Any mass that would require negative fuel should instead be treated -as if it requires zero fuel; the remaining mass, if any, is instead handled by -wishing really hard, which has no mass and is outside the scope of this calculation. +subtract 2. However, that fuel also requires fuel, and that fuel requires fuel, and so on. Any +mass that would require negative fuel should instead be treated as if it requires zero fuel; the +remaining mass, if any, is instead handled by wishing really hard, which has no mass and is outside +the scope of this calculation. So, for each module mass, calculate its fuel and add it to the total. Then, treat the fuel amount you just calculated as the input mass and repeat the process, continuing until a fuel requirement is @@ -17,16 +17,18 @@ zero or negative. For example: - A module of mass 14 requires 2 fuel. This fuel requires no further fuel (2 divided by 3 and rounded down is 0, which would call for a negative fuel), so the total fuel required is still just 2. + - At first, a module of mass 1969 requires 654 fuel. Then, this fuel requires 216 more fuel (654 / 3 - 2). 216 then requires 70 more fuel, which requires 21 fuel, which requires 5 fuel, which requires no further fuel. So, the total fuel required for a module of mass 1969 is 654 + 216 + 70 + 21 + 5 = 966. + - The fuel required by a module of mass 100756 and its fuel is: 33583 + 11192 + 3728 + 1240 + 411 + 135 + 43 + 12 + 2 = 50346. -What is the sum of the fuel requirements for all of the modules on your spacecraft when -also taking into account the mass of the added fuel? (Calculate the fuel requirements for each -module separately, then add them all up at the end.) +What is the sum of the fuel requirements for all of the modules on your spacecraft when also taking +into account the mass of the added fuel? (Calculate the fuel requirements for each module +separately, then add them all up at the end.) diff --git a/02/part1 b/02/part1 @@ -5,28 +5,27 @@ program alarm". On the radio, an Elf is already explaining how to handle the sit worry, that's perfectly norma--" The ship computer bursts into flames. You notify the Elves that the computer's magic smoke seems to have escaped. "That computer ran -Intcode programs like the gravity assist program it was working on; surely there are -enough spare parts up there to build a new Intcode computer!" +Intcode programs like the gravity assist program it was working on; surely there are enough spare +parts up there to build a new Intcode computer!" An Intcode program is a list of integers separated by commas (like 1,0,0,3,99). To run one, start -by looking at the first integer (called position 0). Here, you will find an opcode - -either 1, 2, or 99. The opcode indicates what to do; for example, 99 means that the program is -finished and should immediately halt. Encountering an unknown opcode means something went wrong. +by looking at the first integer (called position 0). Here, you will find an opcode - either 1, 2, or +99. The opcode indicates what to do; for example, 99 means that the program is finished and should +immediately halt. Encountering an unknown opcode means something went wrong. -Opcode 1 adds together numbers read from two positions and stores the result in a third -position. The three integers immediately after the opcode tell you these three -positions - the first two indicate the positions from which you should read the input -values, and the third indicates the position at which the output should be stored. +Opcode 1 adds together numbers read from two positions and stores the result in a third position. +The three integers immediately after the opcode tell you these three positions - the first two +indicate the positions from which you should read the input values, and the third indicates the +position at which the output should be stored. For example, if your Intcode computer encounters 1,10,20,30, it should read the values at positions 10 and 20, add those values, and then overwrite the value at position 30 with their sum. -Opcode 2 works exactly like opcode 1, except it multiplies the two inputs instead of -adding them. Again, the three integers after the opcode indicate where the inputs and -outputs are, not their values. +Opcode 2 works exactly like opcode 1, except it multiplies the two inputs instead of adding them. +Again, the three integers after the opcode indicate where the inputs and outputs are, not their +values. -Once you're done processing an opcode, move to the next one by stepping forward 4 -positions. +Once you're done processing an opcode, move to the next one by stepping forward 4 positions. For example, suppose you have the following program: @@ -41,11 +40,11 @@ For the purposes of illustration, here is the same program split into multiple l The first four integers, 1,9,10,3, are at positions 0, 1, 2, and 3. Together, they represent the first opcode (1, addition), the positions of the two inputs (9 and 10), and the position of the output (3). To handle this opcode, you first need to get the values at the input positions: -position 9 contains 30, and position 10 contains 40. Add these numbers together to get -70. Then, store this value at the output position; here, the output position (3) is at -position 3, so it overwrites itself. Afterward, the program looks like this: +position 9 contains 30, and position 10 contains 40. Add these numbers together to get 70. Then, +store this value at the output position; here, the output position (3) is at position 3, so it +overwrites itself. Afterward, the program looks like this: -1,9,10,70, +1,9,10,70, 2,3,11,0, 99, 30,40,50 @@ -54,7 +53,7 @@ Step forward 4 positions to reach the next opcode, 2. This opcode works just lik it multiplies instead of adding. The inputs are at positions 3 and 11; these positions contain 70 and 50 respectively. Multiplying these produces 3500; this is stored at position 0: -3500,9,10,70, +3500,9,10,70, 2,3,11,0, 99, 30,40,50 @@ -64,15 +63,18 @@ Stepping forward 4 more positions arrives at opcode 99, halting the program. Here are the initial and final states of a few more small programs: - - 1,0,0,0,99 becomes 2,0,0,0,99 (1 + 1 = 2). - - 2,3,0,3,99 becomes 2,3,0,6,99 (3 * 2 = 6). - - 2,4,4,5,99,0 becomes 2,4,4,5,99,9801 (99 * 99 = 9801). - - 1,1,1,4,99,5,6,0,99 becomes 30,1,1,4,2,5,6,0,99. + - 1,0,0,0,99 becomes 2,0,0,0,99 (1 + 1 = 2). + + - 2,3,0,3,99 becomes 2,3,0,6,99 (3 * 2 = 6). + + - 2,4,4,5,99,0 becomes 2,4,4,5,99,9801 (99 * 99 = 9801). + + - 1,1,1,4,99,5,6,0,99 becomes 30,1,1,4,2,5,6,0,99. Once you have a working computer, the first step is to restore the gravity assist program (your puzzle input) to the "1202 program alarm" state it had just before the last computer caught fire. To -do this, before running the program, replace position 1 with the value 12 and replace -position 2 with the value 2. What value is left at position 0 after the program halts? +do this, before running the program, replace position 1 with the value 12 and replace position 2 +with the value 2. What value is left at position 0 after the program halts? diff --git a/02/part2 b/02/part2 @@ -1,42 +1,41 @@ --- Part Two --- -"Good, the new computer seems to be working correctly! Keep it nearby during this -mission - you'll probably use it again. Real Intcode computers support many more features than your -new one, but we'll let you know what they are as you need them." +"Good, the new computer seems to be working correctly! Keep it nearby during this mission - you'll +probably use it again. Real Intcode computers support many more features than your new one, but +we'll let you know what they are as you need them." "However, your current priority should be to complete your gravity assist around the Moon. For this mission to succeed, we should settle on some terminology for the parts you've already built." Intcode programs are given as a list of integers; these values are used as the initial state for the -computer's memory. When you run an Intcode program, make sure to start by initializing -memory to the program's values. A position in memory is called an address (for example, -the first value in memory is at "address 0"). +computer's memory. When you run an Intcode program, make sure to start by initializing memory to the +program's values. A position in memory is called an address (for example, the first value in memory +is at "address 0"). -Opcodes (like 1, 2, or 99) mark the beginning of an instruction. The values used -immediately after an opcode, if any, are called the instruction's parameters. For -example, in the instruction 1,2,3,4, 1 is the opcode; 2, 3, and 4 are the parameters. The -instruction 99 contains only an opcode and has no parameters. +Opcodes (like 1, 2, or 99) mark the beginning of an instruction. The values used immediately after +an opcode, if any, are called the instruction's parameters. For example, in the instruction +1,2,3,4, 1 is the opcode; 2, 3, and 4 are the parameters. The instruction 99 contains only an opcode +and has no parameters. -The address of the current instruction is called the instruction pointer; it starts at -0. After an instruction finishes, the instruction pointer increases by the number of -values in the instruction; until you add more instructions to the computer, this is always 4 (1 -opcode + 3 parameters) for the add and multiply instructions. (The halt instruction would increase -the instruction pointer by 1, but it halts the program instead.) +The address of the current instruction is called the instruction pointer; it starts at 0. After an +instruction finishes, the instruction pointer increases by the number of values in the +instruction; until you add more instructions to the computer, this is always 4 (1 opcode + 3 +parameters) for the add and multiply instructions. (The halt instruction would increase the +instruction pointer by 1, but it halts the program instead.) "With terminology out of the way, we're ready to proceed. To complete the gravity assist, you need -to determine what pair of inputs produces the output 19690720." +to determine what pair of inputs produces the output 19690720." The inputs should still be provided to the program by replacing the values at addresses 1 and 2, -just like before. In this program, the value placed in address 1 is called the noun, -and the value placed in address 2 is called the verb. Each of the two input values -will be between 0 and 99, inclusive. +just like before. In this program, the value placed in address 1 is called the noun, and the value +placed in address 2 is called the verb. Each of the two input values will be between 0 and 99, +inclusive. Once the program has halted, its output is available at address 0, also just like before. Each time -you try a pair of inputs, make sure you first reset the computer's memory to the values in -the program (your puzzle input) - in other words, don't reuse memory from a previous attempt. +you try a pair of inputs, make sure you first reset the computer's memory to the values in the +program (your puzzle input) - in other words, don't reuse memory from a previous attempt. -Find the input noun and verb that cause the program to produce the output -19690720. What is 100 * noun + verb? (For example, if noun=12 and verb=2, the answer -would be 1202.) +Find the input noun and verb that cause the program to produce the output 19690720. What is 100 * +noun + verb? (For example, if noun=12 and verb=2, the answer would be 1202.) diff --git a/03/part1 b/03/part1 @@ -4,15 +4,15 @@ The gravity assist was successful, and you're well on your way to the Venus refu During the rush back on Earth, the fuel management system wasn't completely installed, so that's next on the priority list. -Opening the front panel reveals a jumble of wires. Specifically, two wires are -connected to a central port and extend outward on a grid. You trace the path each wire takes as it -leaves the central port, one wire per line of text (your puzzle input). +Opening the front panel reveals a jumble of wires. Specifically, two wires are connected to a +central port and extend outward on a grid. You trace the path each wire takes as it leaves the +central port, one wire per line of text (your puzzle input). The wires twist and turn, but the two wires occasionally cross paths. To fix the circuit, you need -to find the intersection point closest to the central port. Because the wires are on a -grid, use the Manhattan distance for this measurement. While the wires do technically cross right at -the central port where they both start, this point does not count, nor does a wire count as crossing -with itself. +to find the intersection point closest to the central port. Because the wires are on a grid, use the +Manhattan distance for this measurement. While the wires do technically cross right at the central +port where they both start, this point does not count, nor does a wire count as crossing with +itself. For example, if the first wire's path is R8,U5,L5,D3, then starting from the central port (o), it goes right 8, up 5, left 5, and finally down 3: @@ -35,7 +35,7 @@ Then, if the second wire's path is U7,R6,D4,L4, it goes up 7, right 6, down 4, a .|.....|... .|..+--X-+. .|..|..|.|. -.|.-X--+.|. +.|.-X--+.|. .|..|....|. .|.......|. .o-------+. @@ -54,6 +54,6 @@ U62,R66,U55,R34,D71,R55,D58,R83 = distance 159 U98,R91,D20,R16,D67,R40,U7,R15,U6,R7 = distance 135 -What is the Manhattan distance from the central port to the closest intersection? +What is the Manhattan distance from the central port to the closest intersection? diff --git a/03/part2 b/03/part2 @@ -1,12 +1,12 @@ --- Part Two --- -It turns out that this circuit is very timing-sensitive; you actually need to minimize the -signal delay. +It turns out that this circuit is very timing-sensitive; you actually need to minimize the signal +delay. -To do this, calculate the number of steps each wire takes to reach each intersection; -choose the intersection where the sum of both wires' steps is lowest. If a wire visits -a position on the grid multiple times, use the steps value from the first time it -visits that position when calculating the total value of a specific intersection. +To do this, calculate the number of steps each wire takes to reach each intersection; choose the +intersection where the sum of both wires' steps is lowest. If a wire visits a position on the grid +multiple times, use the steps value from the first time it visits that position when calculating the +total value of a specific intersection. The number of steps a wire takes is the total number of grid squares the wire has entered to get to that location, including the intersection being considered. Again consider the example from above: @@ -23,11 +23,11 @@ that location, including the intersection being considered. Again consider the e ........... In the above example, the intersection closest to the central port is reached after 8+5+5+2 = -20 steps by the first wire and 7+6+4+3 = 20 steps by the second wire for a -total of 20+20 = 40 steps. +20 steps by the first wire and 7+6+4+3 = 20 steps by the second wire for a total of 20+20 = +40 steps. -However, the top-right intersection is better: the first wire takes only 8+5+2 = 15 and -the second wire takes only 7+6+2 = 15, a total of 15+15 = 30 steps. +However, the top-right intersection is better: the first wire takes only 8+5+2 = 15 and the second +wire takes only 7+6+2 = 15, a total of 15+15 = 30 steps. Here are the best steps for the extra examples from above: @@ -39,6 +39,6 @@ U62,R66,U55,R34,D71,R55,D58,R83 = 610 steps U98,R91,D20,R16,D67,R40,U7,R15,U6,R7 = 410 steps -What is the fewest combined steps the wires must take to reach an intersection? +What is the fewest combined steps the wires must take to reach an intersection? diff --git a/04/part1 b/04/part1 @@ -10,10 +10,10 @@ However, they do remember a few key facts about the password: - The value is within the range given in your puzzle input. - - Two adjacent digits are the same (like 22 in 122345). + - Two adjacent digits are the same (like 22 in 122345). - - Going from left to right, the digits never decrease; they only ever increase or stay -the same (like 111123 or 135679). + - Going from left to right, the digits never decrease; they only ever increase or stay the same +(like 111123 or 135679). Other than the range rule, the following are true: @@ -21,12 +21,11 @@ Other than the range rule, the following are true: - 111111 meets these criteria (double 11, never decreases). - - 223450 does not meet these criteria (decreasing pair of digits 50). + - 223450 does not meet these criteria (decreasing pair of digits 50). - 123789 does not meet these criteria (no double). -How many different passwords within the range given in your puzzle input meet these -criteria? +How many different passwords within the range given in your puzzle input meet these criteria? diff --git a/04/part2 b/04/part2 @@ -1,7 +1,7 @@ --- Part Two --- -An Elf just remembered one more important detail: the two adjacent matching digits are not -part of a larger group of matching digits. +An Elf just remembered one more important detail: the two adjacent matching digits are not part of a +larger group of matching digits. Given this additional criterion, but still ignoring the range rule, the following are now true: @@ -9,14 +9,12 @@ Given this additional criterion, but still ignoring the range rule, the followin - 112233 meets these criteria because the digits never decrease and all repeated digits are exactly two digits long. - - 123444 no longer meets the criteria (the repeated 44 is part of a larger group of -444). + - 123444 no longer meets the criteria (the repeated 44 is part of a larger group of 444). - 111122 meets the criteria (even though 1 is repeated more than twice, it still contains a double 22). -How many different passwords within the range given in your puzzle input meet all of -the criteria? +How many different passwords within the range given in your puzzle input meet all of the criteria? diff --git a/05/part1 b/05/part1 @@ -4,36 +4,34 @@ You're starting to sweat as the ship makes its way toward Mercury. The Elves su the air conditioner working by upgrading your ship computer to support the Thermal Environment Supervision Terminal. -The Thermal Environment Supervision Terminal (TEST) starts by running a diagnostic -program (your puzzle input). The TEST diagnostic program will run on your existing Intcode -computer after a few modifications: +The Thermal Environment Supervision Terminal (TEST) starts by running a diagnostic program (your +puzzle input). The TEST diagnostic program will run on your existing Intcode computer after a few +modifications: -First, you'll need to add two new instructions: +First, you'll need to add two new instructions: - - Opcode 3 takes a single integer as input and saves it to the position given by its -only parameter. For example, the instruction 3,50 would take an input value and store it at address -50. + - Opcode 3 takes a single integer as input and saves it to the position given by its only +parameter. For example, the instruction 3,50 would take an input value and store it at address 50. - - Opcode 4 outputs the value of its only parameter. For example, the instruction 4,50 -would output the value at address 50. + - Opcode 4 outputs the value of its only parameter. For example, the instruction 4,50 would output +the value at address 50. Programs that use these instructions will come with documentation that explains what should be connected to the input and output. The program 3,0,4,0,99 outputs whatever it gets as input, then halts. -Second, you'll need to add support for parameter modes: +Second, you'll need to add support for parameter modes: Each parameter of an instruction is handled based on its parameter mode. Right now, your ship -computer already understands parameter mode 0, position mode, which causes the -parameter to be interpreted as a position - if the parameter is 50, its value is -the value stored at address 50 in memory. Until now, all parameters have been in -position mode. +computer already understands parameter mode 0, position mode, which causes the parameter to be +interpreted as a position - if the parameter is 50, its value is the value stored at address 50 in +memory. Until now, all parameters have been in position mode. -Now, your ship computer will also need to handle parameters in mode 1, immediate mode. -In immediate mode, a parameter is interpreted as a value - if the parameter is 50, its -value is simply 50. +Now, your ship computer will also need to handle parameters in mode 1, immediate mode. In immediate +mode, a parameter is interpreted as a value - if the parameter is 50, its value is simply +50. Parameter modes are stored in the same value as the instruction's opcode. The opcode is a two-digit number based only on the ones and tens digit of the value, that is, the opcode is the rightmost two @@ -44,10 +42,9 @@ digit, and so on. Any missing modes are 0. For example, consider the program 1002,4,3,4,33. -The first instruction, 1002,4,3,4, is a multiply instruction - the rightmost two digits -of the first value, 02, indicate opcode 2, multiplication. Then, going right to left, the parameter -modes are 0 (hundreds digit), 1 (thousands digit), and 0 (ten-thousands digit, not present and -therefore zero): +The first instruction, 1002,4,3,4, is a multiply instruction - the rightmost two digits of the first +value, 02, indicate opcode 2, multiplication. Then, going right to left, the parameter modes are 0 +(hundreds digit), 1 (thousands digit), and 0 (ten-thousands digit, not present and therefore zero): ABCDE 1002 @@ -64,35 +61,33 @@ in immediate mode, simply has value 3. The result of this operation, 33 * 3 = 99 according to the third parameter, 4 in position mode, which also works like it did before - 99 is written to address 4. -Parameters that an instruction writes to will never be in immediate mode. +Parameters that an instruction writes to will never be in immediate mode. -Finally, some notes: +Finally, some notes: - - It is important to remember that the instruction pointer should increase by the number -of values in the instruction after the instruction finishes. Because of the new instructions, -this amount is no longer always 4. + - It is important to remember that the instruction pointer should increase by the number of values +in the instruction after the instruction finishes. Because of the new instructions, this amount is +no longer always 4. - Integers can be negative: 1101,100,-1,4,0 is a valid program (find 100 + -1, store the result in position 4). The TEST diagnostic program will start by requesting from the user the ID of the system to test by -running an input instruction - provide it 1, the ID for the ship's air conditioner -unit. +running an input instruction - provide it 1, the ID for the ship's air conditioner unit. It will then perform a series of diagnostic tests confirming that various parts of the Intcode computer, like parameter modes, function correctly. For each test, it will run an -output instruction indicating how far the result of the test was from the expected -value, where 0 means the test was successful. Non-zero outputs mean that a function is not working -correctly; check the instructions that were run before the output instruction to see which one -failed. +output instruction indicating how far the result of the test was from the expected value, where 0 +means the test was successful. Non-zero outputs mean that a function is not working correctly; +check the instructions that were run before the output instruction to see which one failed. -Finally, the program will output a diagnostic code and immediately halt. This final -output isn't an error; an output followed immediately by a halt means the program finished. If all -outputs were zero except the diagnostic code, the diagnostic program ran successfully. +Finally, the program will output a diagnostic code and immediately halt. This final output isn't an +error; an output followed immediately by a halt means the program finished. If all outputs were +zero except the diagnostic code, the diagnostic program ran successfully. -After providing 1 to the only input instruction and passing all the tests, what diagnostic -code does the program produce? +After providing 1 to the only input instruction and passing all the tests, what diagnostic code does +the program produce? diff --git a/05/part2 b/05/part2 @@ -2,7 +2,7 @@ The air conditioner comes online! Its cold air feels good for a while, but then the TEST alarms start to go off. Since the air conditioner can't vent its heat anywhere but back into the -spacecraft, it's actually making the air inside the ship warmer. +spacecraft, it's actually making the air inside the ship warmer. Instead, you'll need to use the TEST to extend the thermal radiators. Fortunately, the diagnostic program (your puzzle input) is already equipped for this. Unfortunately, your Intcode computer is @@ -11,50 +11,49 @@ not. Your computer is only missing a few opcodes: - - Opcode 5 is jump-if-true: if the first parameter is non-zero, it sets -the instruction pointer to the value from the second parameter. Otherwise, it does nothing. + - Opcode 5 is jump-if-true: if the first parameter is non-zero, it sets the instruction pointer to +the value from the second parameter. Otherwise, it does nothing. - - Opcode 6 is jump-if-false: if the first parameter is zero, it sets the -instruction pointer to the value from the second parameter. Otherwise, it does nothing. + - Opcode 6 is jump-if-false: if the first parameter is zero, it sets the instruction pointer to the +value from the second parameter. Otherwise, it does nothing. - - Opcode 7 is less than: if the first parameter is less than the second -parameter, it stores 1 in the position given by the third parameter. Otherwise, it stores 0. + - Opcode 7 is less than: if the first parameter is less than the second parameter, it stores 1 in +the position given by the third parameter. Otherwise, it stores 0. - - Opcode 8 is equals: if the first parameter is equal to the second -parameter, it stores 1 in the position given by the third parameter. Otherwise, it stores 0. + - Opcode 8 is equals: if the first parameter is equal to the second parameter, it stores 1 in the +position given by the third parameter. Otherwise, it stores 0. -Like all instructions, these instructions need to support parameter modes as described -above. +Like all instructions, these instructions need to support parameter modes as described above. Normally, after an instruction is finished, the instruction pointer increases by the number of -values in that instruction. However, if the instruction modifies the instruction -pointer, that value is used and the instruction pointer is not automatically increased. +values in that instruction. However, if the instruction modifies the instruction pointer, that value +is used and the instruction pointer is not automatically increased. For example, here are several programs that take one input, compare it to the value 8, and then produce one output: - - 3,9,8,9,10,9,4,9,99,-1,8 - Using position mode, consider whether the input is -equal to 8; output 1 (if it is) or 0 (if it is not). + - 3,9,8,9,10,9,4,9,99,-1,8 - Using position mode, consider whether the input is equal to 8; output +1 (if it is) or 0 (if it is not). - - 3,9,7,9,10,9,4,9,99,-1,8 - Using position mode, consider whether the input is -less than 8; output 1 (if it is) or 0 (if it is not). + - 3,9,7,9,10,9,4,9,99,-1,8 - Using position mode, consider whether the input is less than 8; output +1 (if it is) or 0 (if it is not). - - 3,3,1108,-1,8,3,4,3,99 - Using immediate mode, consider whether the input is -equal to 8; output 1 (if it is) or 0 (if it is not). + - 3,3,1108,-1,8,3,4,3,99 - Using immediate mode, consider whether the input is equal to 8; output 1 +(if it is) or 0 (if it is not). - - 3,3,1107,-1,8,3,4,3,99 - Using immediate mode, consider whether the input is -less than 8; output 1 (if it is) or 0 (if it is not). + - 3,3,1107,-1,8,3,4,3,99 - Using immediate mode, consider whether the input is less than 8; output +1 (if it is) or 0 (if it is not). Here are some jump tests that take an input, then output 0 if the input was zero or 1 if the input was non-zero: - - 3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9 (using position mode) + - 3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9 (using position mode) - - 3,3,1105,-1,9,1101,0,0,12,4,12,99,1 (using immediate mode) + - 3,3,1105,-1,9,1101,0,0,12,4,12,99,1 (using immediate mode) Here's a larger example: @@ -68,9 +67,9 @@ then output 999 if the input value is below 8, output 1000 if the input value is output 1001 if the input value is greater than 8. This time, when the TEST diagnostic program runs its input instruction to get the ID of the system -to test, provide it 5, the ID for the ship's thermal radiator controller. This -diagnostic test suite only outputs one number, the diagnostic code. +to test, provide it 5, the ID for the ship's thermal radiator controller. This diagnostic test suite +only outputs one number, the diagnostic code. -What is the diagnostic code for system ID 5? +What is the diagnostic code for system ID 5? diff --git a/06/part1 b/06/part1 @@ -22,12 +22,11 @@ with lines) is only partly shown. In the map data, this orbital relationship is which means "BBB is in orbit around AAA". Before you use your map data to plot a course, you need to make sure it wasn't corrupted during the -download. To verify maps, the Universal Orbit Map facility uses orbit count checksums -- the total number of direct orbits (like the one shown above) and indirect -orbits. +download. To verify maps, the Universal Orbit Map facility uses orbit count checksums - the total +number of direct orbits (like the one shown above) and indirect orbits. -Whenever A orbits B and B orbits C, then A indirectly orbits C. This chain can be any -number of objects long: if A orbits B, B orbits C, and C orbits D, then A indirectly orbits D. +Whenever A orbits B and B orbits C, then A indirectly orbits C. This chain can be any number of +objects long: if A orbits B, B orbits C, and C orbits D, then A indirectly orbits D. For example, suppose you have the following map: COM)B @@ -63,9 +62,9 @@ Here, we can count the total number of orbits as follows: - COM orbits nothing. -The total number of direct and indirect orbits in this example is 42. +The total number of direct and indirect orbits in this example is 42. -What is the total number of direct and indirect orbits in your map data? +What is the total number of direct and indirect orbits in your map data? diff --git a/06/part2 b/06/part2 @@ -1,7 +1,7 @@ --- Part Two --- -Now, you just need to figure out how many orbital transfers you (YOU) need to take to -get to Santa (SAN). +Now, you just need to figure out how many orbital transfers you (YOU) need to take to get to Santa +(SAN). You start at the object YOU are orbiting; your destination is the object SAN is orbiting. An orbital transfer lets you move from any object to an object orbiting or orbited by that object. @@ -24,13 +24,13 @@ I)SAN Visually, the above map of orbits looks like this: - YOU - / - G - H J - K - L - / / -COM - B - C - D - E - F - \ - I - SAN + YOU + / + G - H J - K - L + / / +COM - B - C - D - E - F + \ + I - SAN In this example, YOU are in orbit around K, and SAN is in orbit around I. To move from K to I, a minimum of 4 orbital transfers are required: @@ -52,11 +52,10 @@ Afterward, the map of orbits looks like this: COM - B - C - D - E - F \ I - SAN - \ - YOU + \ + YOU -What is the minimum number of orbital transfers required to move from the object YOU -are orbiting to the object SAN is orbiting? (Between the objects they are orbiting - -not between YOU and SAN.) +What is the minimum number of orbital transfers required to move from the object YOU are orbiting to +the object SAN is orbiting? (Between the objects they are orbiting - not between YOU and SAN.) diff --git a/07/part1 b/07/part1 @@ -14,22 +14,20 @@ thrusters. 0 ->| Amp A |->| Amp B |->| Amp C |->| Amp D |->| Amp E |-> (to thrusters) O-------O O-------O O-------O O-------O O-------O -The Elves have sent you some Amplifier Controller Software (your puzzle input), a -program that should run on your existing Intcode computer. Each amplifier will need to run a copy of -the program. +The Elves have sent you some Amplifier Controller Software (your puzzle input), a program that +should run on your existing Intcode computer. Each amplifier will need to run a copy of the program. When a copy of the program starts running on an amplifier, it will first use an input instruction to -ask the amplifier for its current phase setting (an integer from 0 to 4). Each phase -setting is used exactly once, but the Elves can't remember which amplifier needs which -phase setting. +ask the amplifier for its current phase setting (an integer from 0 to 4). Each phase setting is used +exactly once, but the Elves can't remember which amplifier needs which phase setting. The program will then call another input instruction to get the amplifier's input signal, compute the correct output signal, and supply it back to the amplifier with an output instruction. (If the amplifier has not yet received an input signal, it waits until one arrives.) -Your job is to find the largest output signal that can be sent to the thrusters by -trying every possible combination of phase settings on the amplifiers. Make sure that memory is not -shared or reused between copies of the program. +Your job is to find the largest output signal that can be sent to the thrusters by trying every +possible combination of phase settings on the amplifiers. Make sure that memory is not shared or +reused between copies of the program. For example, suppose you want to try the phase setting sequence 3,1,2,4,0, which would mean setting amplifier A to phase setting 3, amplifier B to setting 1, C to 2, D to 4, and E to 0. Then, you @@ -63,19 +61,19 @@ thrusters. Here are some example programs: - - Max thruster signal 43210 (from phase setting sequence 4,3,2,1,0): + - Max thruster signal 43210 (from phase setting sequence 4,3,2,1,0): 3,15,3,16,1002,16,10,16,1,16,15,15,4,15,99,0,0 - - Max thruster signal 54321 (from phase setting sequence 0,1,2,3,4): + - Max thruster signal 54321 (from phase setting sequence 0,1,2,3,4): 3,23,3,24,1002,24,10,24,1002,23,-1,23, 101,5,23,23,1,24,23,23,4,23,99,0,0 - - Max thruster signal 65210 (from phase setting sequence 1,0,4,3,2): + - Max thruster signal 65210 (from phase setting sequence 1,0,4,3,2): 3,31,3,32,1002,32,10,32,1001,31,-2,31,1007,31,0,33, 1002,33,7,33,1,33,31,31,1,32,31,31,4,31,99,0,0,0 -Try every combination of phase settings on the amplifiers. What is the highest signal that -can be sent to the thrusters? +Try every combination of phase settings on the amplifiers. What is the highest signal that can be +sent to the thrusters? diff --git a/07/part2 b/07/part2 @@ -2,7 +2,7 @@ It's no good - in this configuration, the amplifiers can't generate a large enough output signal to produce the thrust you'll need. The Elves quickly talk you through rewiring the amplifiers into a -feedback loop: +feedback loop: O-------O O-------O O-------O O-------O O-------O 0 -+->| Amp A |->| Amp B |->| Amp C |->| Amp D |->| Amp E |-. @@ -14,42 +14,41 @@ produce the thrust you'll need. The Elves quickly talk you through rewiring the (to thrusters) Most of the amplifiers are connected as they were before; amplifier A's output is connected to -amplifier B's input, and so on. However, the output from amplifier E is now connected -into amplifier A's input. This creates the feedback loop: the signal will be sent through the -amplifiers many times. +amplifier B's input, and so on. However, the output from amplifier E is now connected into amplifier +A's input. This creates the feedback loop: the signal will be sent through the amplifiers +many times. -In feedback loop mode, the amplifiers need totally different phase settings: integers -from 5 to 9, again each used exactly once. These settings will cause the Amplifier Controller -Software to repeatedly take input and produce output many times before halting. Provide each -amplifier its phase setting at its first input instruction; all further input/output instructions -are for signals. +In feedback loop mode, the amplifiers need totally different phase settings: integers from 5 to 9, +again each used exactly once. These settings will cause the Amplifier Controller Software to +repeatedly take input and produce output many times before halting. Provide each amplifier its phase +setting at its first input instruction; all further input/output instructions are for signals. Don't restart the Amplifier Controller Software on any amplifier during this process. Each one should continue receiving and sending signals until it halts. All signals sent or received in this process will be between pairs of amplifiers except the very first signal and the very last signal. To start the process, a 0 signal is sent to amplifier A's -input exactly once. +input exactly once. Eventually, the software on the amplifiers will halt after they have processed the final loop. When this happens, the last output signal from amplifier E is sent to the thrusters. Your job is to -find the largest output signal that can be sent to the thrusters using the new phase -settings and feedback loop arrangement. +find the largest output signal that can be sent to the thrusters using the new phase settings and +feedback loop arrangement. Here are some example programs: - - Max thruster signal 139629729 (from phase setting sequence 9,8,7,6,5): + - Max thruster signal 139629729 (from phase setting sequence 9,8,7,6,5): 3,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26, 27,4,27,1001,28,-1,28,1005,28,6,99,0,0,5 - - Max thruster signal 18216 (from phase setting sequence 9,7,8,5,6): + - Max thruster signal 18216 (from phase setting sequence 9,7,8,5,6): 3,52,1001,52,-5,52,3,53,1,52,56,54,1007,54,5,55,1005,55,26,1001,54, -5,54,1105,1,12,1,53,54,53,1008,54,0,55,1001,55,1,55,2,53,55,53,4, 53,1001,56,-1,56,1005,56,6,99,0,0,0,0,10 -Try every combination of the new phase settings on the amplifier feedback loop. What is -the highest signal that can be sent to the thrusters? +Try every combination of the new phase settings on the amplifier feedback loop. What is the highest +signal that can be sent to the thrusters? diff --git a/08/part1 b/08/part1 @@ -16,8 +16,8 @@ Images are sent as a series of digits that each represent the color of a single fill each row of the image left-to-right, then move downward to the next row, filling rows top-to-bottom until every pixel of the image is filled. -Each image actually consists of a series of identically-sized layers that are filled in -this way. So, the first digit corresponds to the top-left pixel of the first layer, the second digit +Each image actually consists of a series of identically-sized layers that are filled in this way. +So, the first digit corresponds to the top-left pixel of the first layer, the second digit corresponds to the pixel to the right of that on the same layer, and so on until the last digit, which corresponds to the bottom-right pixel of the last layer. @@ -30,10 +30,10 @@ Layer 1: 123 Layer 2: 789 012 -The image you received is 25 pixels wide and 6 pixels tall. +The image you received is 25 pixels wide and 6 pixels tall. To make sure the image wasn't corrupted during transmission, the Elves would like you to find the -layer that contains the fewest 0 digits. On that layer, what is the number of -1 digits multiplied by the number of 2 digits? +layer that contains the fewest 0 digits. On that layer, what is the number of 1 digits multiplied +by the number of 2 digits? diff --git a/08/part2 b/08/part2 @@ -6,37 +6,34 @@ pixel: 0 is black, 1 is white, and 2 is transparent. The layers are rendered with the first layer in front and the last layer in back. So, if a given position has a transparent pixel in the first and second layers, a black pixel in the third layer, -and a white pixel in the fourth layer, the final image would have a black pixel at that -position. +and a white pixel in the fourth layer, the final image would have a black pixel at that position. For example, given an image 2 pixels wide and 2 pixels tall, the image data 0222112222120000 corresponds to the following image layers: -Layer 1: 02 +Layer 1: 02 22 -Layer 2: 11 +Layer 2: 11 22 Layer 3: 22 - 12 + 12 Layer 4: 00 - 00 + 00 Then, the full image can be found by determining the top visible pixel in each position: - - The top-left pixel is black because the top layer is 0. + - The top-left pixel is black because the top layer is 0. - - The top-right pixel is white because the top layer is 2 (transparent), but the -second layer is 1. + - The top-right pixel is white because the top layer is 2 (transparent), but the second layer is 1. - - The bottom-left pixel is white because the top two layers are 2, but the third layer -is 1. + - The bottom-left pixel is white because the top two layers are 2, but the third layer is 1. - - The bottom-right pixel is black because the only visible pixel in that position is 0 -(from layer 4). + - The bottom-right pixel is black because the only visible pixel in that position is 0 (from layer +4). So, the final image looks like this: @@ -44,6 +41,6 @@ So, the final image looks like this: 01 10 -What message is produced after decoding your image? +What message is produced after decoding your image? diff --git a/09/part1 b/09/part1 @@ -4,35 +4,34 @@ You've just said goodbye to the rebooted rover and left Mars when you receive a signal coming from the asteroid belt. It must be the Ceres monitoring station! In order to lock on to the signal, you'll need to boost your sensors. The Elves send up the latest -BOOST program - Basic Operation Of System Test. +BOOST program - Basic Operation Of System Test. While BOOST (your puzzle input) is capable of boosting your sensors, for tenuous safety reasons, it refuses to do so until the computer it runs on passes some checks to demonstrate it is a -complete Intcode computer. +complete Intcode computer. Your existing Intcode computer is missing one key feature: it needs support for parameters in -relative mode. +relative mode. -Parameters in mode 2, relative mode, behave very similarly to parameters in -position mode: the parameter is interpreted as a position. Like position mode, -parameters in relative mode can be read from or written to. +Parameters in mode 2, relative mode, behave very similarly to parameters in position mode: the +parameter is interpreted as a position. Like position mode, parameters in relative mode can be read +from or written to. The important difference is that relative mode parameters don't count from address 0. Instead, they -count from a value called the relative base. The relative base starts at -0. +count from a value called the relative base. The relative base starts at 0. -The address a relative mode parameter refers to is itself plus the current -relative base. When the relative base is 0, relative mode parameters and position mode -parameters with the same value refer to the same address. +The address a relative mode parameter refers to is itself plus the current relative base. When the +relative base is 0, relative mode parameters and position mode parameters with the same value refer +to the same address. For example, given a relative base of 50, a relative mode parameter of -7 refers to memory address -50 + -7 = 43. +50 + -7 = 43. -The relative base is modified with the relative base offset instruction: +The relative base is modified with the relative base offset instruction: - - Opcode 9 adjusts the relative base by the value of its only parameter. The relative -base increases (or decreases, if the value is negative) by the value of the parameter. + - Opcode 9 adjusts the relative base by the value of its only parameter. The relative base +increases (or decreases, if the value is negative) by the value of the parameter. For example, if the relative base is 2000, then after the instruction 109,19, the relative base @@ -66,6 +65,6 @@ modes) that seem to be functioning incorrectly, and finally output a BOOST keyco Once your Intcode computer is fully functional, the BOOST program should report no malfunctioning opcodes when run in test mode; it should only output a single value, the BOOST keycode. -What BOOST keycode does it produce? +What BOOST keycode does it produce? diff --git a/09/part2 b/09/part2 @@ -1,16 +1,15 @@ --- Part Two --- -You now have a complete Intcode computer. +You now have a complete Intcode computer. Finally, you can lock on to the Ceres distress signal! You just need to boost your sensors using the BOOST program. The program runs in sensor boost mode by providing the input instruction the value 2. Once run, it will boost the sensors automatically, but it might take a few seconds to complete the operation on -slower hardware. In sensor boost mode, the program will output a single value: the -coordinates of the distress signal. +slower hardware. In sensor boost mode, the program will output a single value: the coordinates of +the distress signal. -Run the BOOST program in sensor boost mode. What are the coordinates of the distress -signal? +Run the BOOST program in sensor boost mode. What are the coordinates of the distress signal? diff --git a/10/part1 b/10/part1 @@ -12,12 +12,11 @@ position. The asteroids can be described with X,Y coordinates where X is the di edge and Y is the distance from the top edge (so the top-left corner is 0,0 and the position immediately to its right is 1,0). -Your job is to figure out which asteroid would be the best place to build a new monitoring -station. A monitoring station can detect any asteroid to which it has -direct line of sight - that is, there cannot be another asteroid exactly -between them. This line of sight can be at any angle, not just lines aligned to the grid or -diagonally. The best location is the asteroid that can detect the largest -number of other asteroids. +Your job is to figure out which asteroid would be the best place to build a new monitoring +station. A monitoring station can detect any asteroid to which it has direct line of sight - that +is, there cannot be another asteroid exactly between them. This line of sight can be at any angle, +not just lines aligned to the grid or diagonally. The best location is the asteroid that can +detect the largest number of other asteroids. For example, consider the following map: @@ -25,7 +24,7 @@ For example, consider the following map: ..... ##### ....# -...## +...## The best location for a new monitoring station on this map is the highlighted asteroid at 3,4 because it can detect 8 asteroids, more than any other location. (The only asteroid it cannot detect @@ -67,7 +66,7 @@ Here are some larger examples: ..#....#.# #..#....#. .##.#..### -##...#..#. +##...#..#. .#....#### @@ -75,7 +74,7 @@ Here are some larger examples: #.#...#.#. .###....#. -.#....#... +.#....#... ##.#.#.#.# ....#.#.#. .##..###.# @@ -90,7 +89,7 @@ Here are some larger examples: .#..#..### ####.###.# ....###.#. -..###.##.# +..###.##.# ##.##.#.#. ....###..# ..#.#..#.# @@ -114,7 +113,7 @@ Here are some larger examples: ..######..##.####### ####.##.####...##..# .#####..#.######.### -##...#.##########... +##...#.##########... #.##########.####### .####.#.###.###.#.## ....##.##.###..##### @@ -124,7 +123,7 @@ Here are some larger examples: -Find the best location for a new monitoring station. How many other asteroids can be -detected from that location? +Find the best location for a new monitoring station. How many other asteroids can be detected from +that location? diff --git a/10/part2 b/10/part2 @@ -3,17 +3,17 @@ Once you give them the coordinates, the Elves quickly deploy an Instant Monitoring Station to the location and discover the worst: there are simply too many asteroids. -The only solution is complete vaporization by giant laser. +The only solution is complete vaporization by giant laser. Fortunately, in addition to an asteroid scanner, the new monitoring station also comes equipped with a giant rotating laser perfect for vaporizing asteroids. The laser starts by pointing -up and always rotates clockwise, vaporizing any asteroid it hits. +up and always rotates clockwise, vaporizing any asteroid it hits. -If multiple asteroids are exactly in line with the station, the laser only has enough -power to vaporize one of them before continuing its rotation. In other words, the same -asteroids that can be detected can be vaporized, but if vaporizing one asteroid makes -another one detectable, the newly-detected asteroid won't be vaporized until the laser has returned -to the same position by rotating a full 360 degrees. +If multiple asteroids are exactly in line with the station, the laser only has enough power to +vaporize one of them before continuing its rotation. In other words, the same asteroids that can be +detected can be vaporized, but if vaporizing one asteroid makes another one detectable, the +newly-detected asteroid won't be vaporized until the laser has returned to the same position by +rotating a full 360 degrees. For example, consider the following map, where the asteroid with the new monitoring station (and laser) is marked X: @@ -26,9 +26,9 @@ laser) is marked X: The first nine asteroids to get vaporized, in order, would be: -.#....###24...#.. -##...##.13#67..9# -##...#...5.8####. +.#....###24...#.. +##...##.13#67..9# +##...#...5.8####. ..#.....X...###.. ..#.#.....#....## @@ -38,25 +38,25 @@ vaporized are: .#....###.....#.. ##...##...#.....# -##...#......1234. -..#.....X...5##.. -..#.9.....8....76 +##...#......1234. +..#.....X...5##.. +..#.9.....8....76 The next nine to be vaporized are then: -.8....###.....#.. -56...9#...#.....# -34...7........... -..2.....X....##.. -..1.............. +.8....###.....#.. +56...9#...#.....# +34...7........... +..2.....X....##.. +..1.............. Finally, the laser completes its first full rotation (1 through 3), a second rotation (4 through 8), and vaporizes the last asteroid (9) partway through its third rotation: -......234.....6.. -......1...5.....7 +......234.....6.. +......1...5.....7 ................. -........X....89.. +........X....89.. ................. In the large example above (the one with the best monitoring station location at 11,13): @@ -78,15 +78,15 @@ In the large example above (the one with the best monitoring station location at - The 199th asteroid to be vaporized is at 9,6. - - The 200th asteroid to be vaporized is at 8,2. + - The 200th asteroid to be vaporized is at 8,2. - The 201st asteroid to be vaporized is at 10,9. - The 299th and final asteroid to be vaporized is at 11,1. -The Elves are placing bets on which will be the 200th asteroid to be vaporized. Win -the bet by determining which asteroid that will be; what do you get if you multiply its X -coordinate by 100 and then add its Y coordinate? (For example, 8,2 becomes 802.) +The Elves are placing bets on which will be the 200th asteroid to be vaporized. Win the bet by +determining which asteroid that will be; what do you get if you multiply its X coordinate by 100 and +then add its Y coordinate? (For example, 8,2 becomes 802.) diff --git a/11/part1 b/11/part1 @@ -1,39 +1,35 @@ --- Day 11: Space Police --- -On the way to Jupiter, you're pulled over by the Space Police. +On the way to Jupiter, you're pulled over by the Space Police. "Attention, unmarked spacecraft! You are in violation of Space Law! All spacecraft must have a -clearly visible registration identifier! You have 24 hours to comply or be sent to -Space Jail!" +clearly visible registration identifier! You have 24 hours to comply or be sent to Space Jail!" Not wanting to be sent to Space Jail, you radio back to the Elves on Earth for help. Although it takes almost three hours for their reply signal to reach you, they send instructions for how to -power up the emergency hull painting robot and even provide a small Intcode program -(your puzzle input) that will cause it to paint your ship appropriately. +power up the emergency hull painting robot and even provide a small Intcode program (your puzzle +input) that will cause it to paint your ship appropriately. There's just one problem: you don't have an emergency hull painting robot. You'll need to build a new emergency hull painting robot. The robot needs to be able to move around on the grid of square panels on the side of your ship, detect the color of its current panel, and -paint its current panel black or white. (All of the panels are currently -black.) +paint its current panel black or white. (All of the panels are currently black.) The Intcode program will serve as the brain of the robot. The program uses input instructions to -access the robot's camera: provide 0 if the robot is over a black panel or 1 if the -robot is over a white panel. Then, the program will output two values: +access the robot's camera: provide 0 if the robot is over a black panel or 1 if the robot is over a +white panel. Then, the program will output two values: - - First, it will output a value indicating the color to paint the panel the robot is -over: 0 means to paint the panel black, and 1 means to paint the panel -white. + - First, it will output a value indicating the color to paint the panel the robot is over: 0 means +to paint the panel black, and 1 means to paint the panel white. - - Second, it will output a value indicating the direction the robot should turn: 0 -means it should turn left 90 degrees, and 1 means it should turn right 90 -degrees. + - Second, it will output a value indicating the direction the robot should turn: 0 means it should +turn left 90 degrees, and 1 means it should turn right 90 degrees. -After the robot turns, it should always move forward exactly one panel. The robot -starts facing up. +After the robot turns, it should always move forward exactly one panel. The robot starts facing +up. The robot will continue running for a while like this and halt when it is finished drawing. Do not restart the Intcode computer inside the robot during this process. @@ -86,12 +82,11 @@ should be provided 1. After several more outputs (0,1, 1,0, 1,0), the area look ..... Before you deploy the robot, you should probably have an estimate of the area it will cover: -specifically, you need to know the number of panels it paints at least once, regardless -of color. In the example above, the robot painted 6 panels at least once. (It painted -its starting panel twice, but that panel is still only counted once; it also never painted the panel -it ended on.) +specifically, you need to know the number of panels it paints at least once, regardless of color. In +the example above, the robot painted 6 panels at least once. (It painted its starting panel twice, +but that panel is still only counted once; it also never painted the panel it ended on.) -Build a new emergency hull painting robot and run the Intcode program on it. How many -panels does it paint at least once? +Build a new emergency hull painting robot and run the Intcode program on it. How many panels does it +paint at least once? diff --git a/11/part2 b/11/part2 @@ -1,15 +1,14 @@ --- Part Two --- -You're not sure what it's trying to paint, but it's definitely not a registration -identifier. The Space Police are getting impatient. +You're not sure what it's trying to paint, but it's definitely not a registration identifier. The +Space Police are getting impatient. Checking your external ship cameras again, you notice a white panel marked "emergency hull painting -robot starting panel". The rest of the panels are still black, but it looks like the -robot was expecting to start on a white panel, not a black one. +robot starting panel". The rest of the panels are still black, but it looks like the robot was +expecting to start on a white panel, not a black one. Based on the Space Law Space Brochure that the Space Police attached to one of your windows, a valid -registration identifier is always eight capital letters. After starting the robot on a -single white panel instead, what registration identifier does it paint on -your hull? +registration identifier is always eight capital letters. After starting the robot on a single +white panel instead, what registration identifier does it paint on your hull? diff --git a/12/part1 b/12/part1 @@ -2,31 +2,29 @@ The space near Jupiter is not a very safe place; you need to be careful of a big distracting red spot, extreme radiation, and a whole lot of moons swirling around. You decide to start by tracking -the four largest moons: Io, Europa, Ganymede, and -Callisto. +the four largest moons: Io, Europa, Ganymede, and Callisto. -After a brief scan, you calculate the position of each moon (your puzzle input). You -just need to simulate their motion so you can avoid them. +After a brief scan, you calculate the position of each moon (your puzzle input). You just need to +simulate their motion so you can avoid them. Each moon has a 3-dimensional position (x, y, and z) and a 3-dimensional velocity. The position of each moon is given in your scan; the x, y, and z velocity of each moon starts at 0. -Simulate the motion of the moons in time steps. Within each time step, first update the -velocity of every moon by applying gravity. Then, once all moons' velocities have been -updated, update the position of every moon by applying velocity. Time progresses by one -step once all of the positions are updated. +Simulate the motion of the moons in time steps. Within each time step, first update the velocity of +every moon by applying gravity. Then, once all moons' velocities have been updated, update the +position of every moon by applying velocity. Time progresses by one step once all of the positions +are updated. -To apply gravity, consider every pair of moons. On each axis (x, y, and -z), the velocity of each moon changes by exactly +1 or -1 to pull the moons together. -For example, if Ganymede has an x position of 3, and Callisto has a x position of 5, then Ganymede's -x velocity changes by +1 (because 5 > 3) and Callisto's x velocity changes by --1 (because 3 < 5). However, if the positions on a given axis are the same, the velocity on that -axis does not change for that pair of moons. +To apply gravity, consider every pair of moons. On each axis (x, y, and z), the velocity of each +moon changes by exactly +1 or -1 to pull the moons together. For example, if Ganymede has an x +position of 3, and Callisto has a x position of 5, then Ganymede's x velocity changes by +1 (because +5 > 3) and Callisto's x velocity changes by -1 (because 3 < 5). However, if the positions on a given +axis are the same, the velocity on that axis does not change for that pair of moons. -Once all gravity has been applied, apply velocity: simply add the velocity of each moon -to its own position. For example, if Europa has a position of x=1, y=2, z=3 and a velocity of x=-2, -y=0,z=3, then its new position would be x=-1, y=2, z=6. This process does not modify the velocity of -any moon. +Once all gravity has been applied, apply velocity: simply add the velocity of each moon to its own +position. For example, if Europa has a position of x=1, y=2, z=3 and a velocity of x=-2, y=0,z=3, +then its new position would be x=-1, y=2, z=6. This process does not modify the velocity of any +moon. For example, suppose your scan reveals the following positions: @@ -103,22 +101,21 @@ pos=<x= 1, y=-8, z= 0>, vel=<x=-1, y= 1, z= 3> pos=<x= 3, y=-6, z= 1>, vel=<x= 3, y= 2, z=-3> pos=<x= 2, y= 0, z= 4>, vel=<x= 1, y=-1, z=-1> -Then, it might help to calculate the total energy in the system. The total energy for a -single moon is its potential energy multiplied by its kinetic energy. A -moon's potential energy is the sum of the absolute values of its x, y, and z position -coordinates. A moon's kinetic energy is the sum of the absolute values of its velocity -coordinates. Below, each line shows the calculations for a moon's potential energy (pot), kinetic -energy (kin), and total energy: +Then, it might help to calculate the total energy in the system. The total energy for a single moon +is its potential energy multiplied by its kinetic energy. A moon's potential energy is the sum of +the absolute values of its x, y, and z position coordinates. A moon's kinetic energy is the sum of +the absolute values of its velocity coordinates. Below, each line shows the calculations for a +moon's potential energy (pot), kinetic energy (kin), and total energy: Energy after 10 steps: pot: 2 + 1 + 3 = 6; kin: 3 + 2 + 1 = 6; total: 6 * 6 = 36 pot: 1 + 8 + 0 = 9; kin: 1 + 1 + 3 = 5; total: 9 * 5 = 45 pot: 3 + 6 + 1 = 10; kin: 3 + 2 + 3 = 8; total: 10 * 8 = 80 pot: 2 + 0 + 4 = 6; kin: 1 + 1 + 1 = 3; total: 6 * 3 = 18 -Sum of total energy: 36 + 45 + 80 + 18 = 179 +Sum of total energy: 36 + 45 + 80 + 18 = 179 In the above example, adding together the total energy for all moons after 10 steps produces the -total energy in the system, 179. +total energy in the system, 179. Here's a second example: @@ -200,9 +197,8 @@ pot: 8 + 12 + 9 = 29; kin: 7 + 3 + 0 = 10; total: 29 * 10 = 290 pot: 13 + 16 + 3 = 32; kin: 3 + 11 + 5 = 19; total: 32 * 19 = 608 pot: 29 + 11 + 1 = 41; kin: 3 + 7 + 4 = 14; total: 41 * 14 = 574 pot: 16 + 13 + 23 = 52; kin: 7 + 1 + 1 = 9; total: 52 * 9 = 468 -Sum of total energy: 290 + 608 + 574 + 468 = 1940 +Sum of total energy: 290 + 608 + 574 + 468 = 1940 -What is the total energy in the system after simulating the moons given in your scan -for 1000 steps? +What is the total energy in the system after simulating the moons given in your scan for 1000 steps? diff --git a/12/part2 b/12/part2 @@ -3,8 +3,8 @@ All this drifting around in space makes you wonder about the nature of the universe. Does history really repeat itself? You're curious whether the moons will ever return to a previous state. -Determine the number of steps that must occur before all of the moons' -positions and velocities exactly match a previous point in time. +Determine the number of steps that must occur before all of the moons' positions and velocities +exactly match a previous point in time. For example, the first example above takes 2772 steps before they exactly match a previous point in time; it eventually returns to the initial state: @@ -33,8 +33,8 @@ pos=<x= 2, y=-10, z= -7>, vel=<x= 0, y= 0, z= 0> pos=<x= 4, y= -8, z= 8>, vel=<x= 0, y= 0, z= 0> pos=<x= 3, y= 5, z= -1>, vel=<x= 0, y= 0, z= 0> -Of course, the universe might last for a very long time before repeating. Here's a -copy of the second example from above: +Of course, the universe might last for a very long time before repeating. Here's a copy of the +second example from above: <x=-8, y=-10, z=0> <x=5, y=5, z=10> @@ -42,9 +42,8 @@ copy of the second example from above: <x=9, y=-8, z=-3> This set of initial positions takes 4686774924 steps before it repeats a previous state! Clearly, -you might need to find a more efficient way to simulate the universe. +you might need to find a more efficient way to simulate the universe. -How many steps does it take to reach the first state that exactly matches a previous -state? +How many steps does it take to reach the first state that exactly matches a previous state? diff --git a/13/part1 b/13/part1 @@ -4,32 +4,31 @@ As you ponder the solitude of space and the ever-increasing three-hour roundtrip between you and Earth, you notice that the Space Mail Indicator Light is blinking. To help keep you sane, the Elves have sent you a care package. -It's a new game for the ship's arcade cabinet! Unfortunately, the arcade is all the way -on the other end of the ship. Surely, it won't be hard to build your own - the care package even -comes with schematics. +It's a new game for the ship's arcade cabinet! Unfortunately, the arcade is all the way on the other +end of the ship. Surely, it won't be hard to build your own - the care package even comes with +schematics. The arcade cabinet runs Intcode software like the game the Elves sent (your puzzle input). It has a -primitive screen capable of drawing square tiles on a grid. The software draws tiles -to the screen with output instructions: every three output instructions specify the x position -(distance from the left), y position (distance from the top), and tile id. The tile id is -interpreted as follows: +primitive screen capable of drawing square tiles on a grid. The software draws tiles to the screen +with output instructions: every three output instructions specify the x position (distance from the +left), y position (distance from the top), and tile id. The tile id is interpreted as follows: - - 0 is an empty tile. No game object appears in this tile. + - 0 is an empty tile. No game object appears in this tile. - - 1 is a wall tile. Walls are indestructible barriers. + - 1 is a wall tile. Walls are indestructible barriers. - - 2 is a block tile. Blocks can be broken by the ball. + - 2 is a block tile. Blocks can be broken by the ball. - - 3 is a horizontal paddle tile. The paddle is indestructible. + - 3 is a horizontal paddle tile. The paddle is indestructible. - - 4 is a ball tile. The ball moves diagonally and bounces off objects. + - 4 is a ball tile. The ball moves diagonally and bounces off objects. -For example, a sequence of output values like 1,2,3,6,5,4 would draw a horizontal -paddle tile (1 tile from the left and 2 tiles from the top) and a ball tile (6 -tiles from the left and 5 tiles from the top). +For example, a sequence of output values like 1,2,3,6,5,4 would draw a horizontal paddle tile (1 +tile from the left and 2 tiles from the top) and a ball tile (6 tiles from the left and 5 tiles from +the top). -Start the game. How many block tiles are on the screen when the game exits? +Start the game. How many block tiles are on the screen when the game exits? diff --git a/13/part2 b/13/part2 @@ -8,11 +8,11 @@ The arcade cabinet has a joystick that can move left and right. The software re the joystick with input instructions: - - If the joystick is in the neutral position, provide 0. + - If the joystick is in the neutral position, provide 0. - - If the joystick is tilted to the left, provide -1. + - If the joystick is tilted to the left, provide -1. - - If the joystick is tilted to the right, provide 1. + - If the joystick is tilted to the right, provide 1. The arcade cabinet also has a segment display capable of showing a single number that represents the @@ -21,7 +21,6 @@ instruction is not a tile; the value instead specifies the new score to show in For example, a sequence of output values like -1,0,12345 would show 12345 as the player's current score. -Beat the game by breaking all the blocks. What is your score after the last block is -broken? +Beat the game by breaking all the blocks. What is your score after the last block is broken? diff --git a/14/part1 b/14/part1 @@ -1,16 +1,17 @@ --- Day 14: Space Stoichiometry --- -As you approach the rings of Saturn, your ship's low fuel indicator turns on. There isn't any fuel +As you approach the rings of Saturn, your ship's low fuel indicator turns on. There isn't any fuel here, but the rings have plenty of raw material. Perhaps your ship's Inter-Stellar Refinery Union -brand nanofactory can turn these raw materials into fuel. +brand nanofactory can turn these raw materials into fuel. -You ask the nanofactory to produce a list of the reactions it can perform that are relevant to this -process (your puzzle input). Every reaction turns some quantities of specific input chemicals into -some quantity of an output chemical. Almost every chemical is produced by exactly one reaction; the +You ask the nanofactory to produce a list of the reactions it can perform that are relevant to this +process (your puzzle input). Every reaction turns some quantities of specific input chemicals into +some quantity of an output chemical. Almost every chemical is produced by exactly one reaction; the only exception, ORE, is the raw material input to the entire process and is not produced by a reaction. -You just need to know how much ORE you'll need to collect before you can produce one unit of FUEL. +You just need to know how much ORE you'll need to collect before you can produce one unit of +FUEL. Each reaction gives specific quantities for its inputs and output; reactions cannot be partially run, so only whole integer multiples of these quantities can be used. (It's okay to have leftover @@ -30,7 +31,7 @@ Suppose your nanofactory produces the following list of reactions: The first two reactions use only ORE as inputs; they indicate that you can produce as much of chemical A as you want (in increments of 10 units, each 10 costing 10 ORE) and as much of chemical B -as you want (each costing 1 ORE). To produce 1 FUEL, a total of 31 ORE is required: 1 ORE to +as you want (each costing 1 ORE). To produce 1 FUEL, a total of 31 ORE is required: 1 ORE to produce 1 B, then 30 more ORE to produce the 7 + 7 + 7 + 7 = 28 A (with 2 extra A wasted) required in the reactions to convert the B into C, C into D, D into E, and finally E into FUEL. (30 A is produced because its reaction requires that it is created in increments of 10.) @@ -45,7 +46,7 @@ Or, suppose you have the following list of reactions: 4 C, 1 A => 1 CA 2 AB, 3 BC, 4 CA => 1 FUEL -The above list of reactions requires 165 ORE to produce 1 FUEL: +The above list of reactions requires 165 ORE to produce 1 FUEL: - Consume 45 ORE to produce 10 A. @@ -66,7 +67,7 @@ The above list of reactions requires 165 ORE to produce 1 FUEL: Here are some larger examples: - - 13312 ORE for 1 FUEL: + - 13312 ORE for 1 FUEL: 157 ORE => 5 NZVS 165 ORE => 6 DCFZ @@ -79,7 +80,7 @@ Here are some larger examples: 3 DCFZ, 7 NZVS, 5 HKGWZ, 10 PSHF => 8 KHKGT - - 180697 ORE for 1 FUEL: + - 180697 ORE for 1 FUEL: 2 VPVL, 7 FWMGM, 2 CXFTF, 11 MNCFX => 1 STKFG 17 NVRVD, 3 JNWZP => 8 VPVL @@ -95,7 +96,7 @@ Here are some larger examples: 176 ORE => 6 VJHF - - 2210736 ORE for 1 FUEL: + - 2210736 ORE for 1 FUEL: 171 ORE => 8 CNZTR 7 ZLQW, 3 BMBT, 9 XCVML, 26 XMNCP, 1 WPTQ, 2 MZWV, 1 RJRHP => 4 PLWSL @@ -117,7 +118,7 @@ Here are some larger examples: -Given the list of reactions in your puzzle input, what is the minimum amount of ORE required to -produce exactly 1 FUEL? +Given the list of reactions in your puzzle input, what is the minimum amount of ORE required to +produce exactly 1 FUEL? diff --git a/14/part2 b/14/part2 @@ -1,123 +1,18 @@ ---- Day 14: Space Stoichiometry --- +--- Part Two --- -As you approach the rings of Saturn, your ship's low fuel indicator turns on. There isn't any fuel -here, but the rings have plenty of raw material. Perhaps your ship's Inter-Stellar Refinery Union -brand nanofactory can turn these raw materials into fuel. +After collecting ORE for a while, you check your cargo hold: 1 trillion (1000000000000) units of +ORE. -You ask the nanofactory to produce a list of the reactions it can perform that are relevant to this -process (your puzzle input). Every reaction turns some quantities of specific input chemicals into -some quantity of an output chemical. Almost every chemical is produced by exactly one reaction; the -only exception, ORE, is the raw material input to the entire process and is not produced by a -reaction. +With that much ore, given the examples above: -You just need to know how much ORE you'll need to collect before you can produce one unit of FUEL. -Each reaction gives specific quantities for its inputs and output; reactions cannot be partially -run, so only whole integer multiples of these quantities can be used. (It's okay to have leftover -chemicals when you're done, though.) For example, the reaction 1 A, 2 B, 3 C => 2 D means that -exactly 2 units of chemical D can be produced by consuming exactly 1 A, 2 B and 3 C. You can run -the full reaction as many times as necessary; for example, you could produce 10 D by consuming 5 A, -10 B, and 15 C. + - The 13312 ORE-per-FUEL example could produce 82892753 FUEL. -Suppose your nanofactory produces the following list of reactions: + - The 180697 ORE-per-FUEL example could produce 5586022 FUEL. -10 ORE => 10 A -1 ORE => 1 B -7 A, 1 B => 1 C -7 A, 1 C => 1 D -7 A, 1 D => 1 E -7 A, 1 E => 1 FUEL + - The 2210736 ORE-per-FUEL example could produce 460664 FUEL. -The first two reactions use only ORE as inputs; they indicate that you can produce as much of -chemical A as you want (in increments of 10 units, each 10 costing 10 ORE) and as much of chemical B -as you want (each costing 1 ORE). To produce 1 FUEL, a total of 31 ORE is required: 1 ORE to -produce 1 B, then 30 more ORE to produce the 7 + 7 + 7 + 7 = 28 A (with 2 extra A wasted) required -in the reactions to convert the B into C, C into D, D into E, and finally E into FUEL. (30 A is -produced because its reaction requires that it is created in increments of 10.) -Or, suppose you have the following list of reactions: - -9 ORE => 2 A -8 ORE => 3 B -7 ORE => 5 C -3 A, 4 B => 1 AB -5 B, 7 C => 1 BC -4 C, 1 A => 1 CA -2 AB, 3 BC, 4 CA => 1 FUEL - -The above list of reactions requires 165 ORE to produce 1 FUEL: - - - - Consume 45 ORE to produce 10 A. - - - Consume 64 ORE to produce 24 B. - - - Consume 56 ORE to produce 40 C. - - - Consume 6 A, 8 B to produce 2 AB. - - - Consume 15 B, 21 C to produce 3 BC. - - - Consume 16 C, 4 A to produce 4 CA. - - - Consume 2 AB, 3 BC, 4 CA to produce 1 FUEL. - - -Here are some larger examples: - - - - 13312 ORE for 1 FUEL: - -157 ORE => 5 NZVS -165 ORE => 6 DCFZ -44 XJWVT, 5 KHKGT, 1 QDVJ, 29 NZVS, 9 GPVTF, 48 HKGWZ => 1 FUEL -12 HKGWZ, 1 GPVTF, 8 PSHF => 9 QDVJ -179 ORE => 7 PSHF -177 ORE => 5 HKGWZ -7 DCFZ, 7 PSHF => 2 XJWVT -165 ORE => 2 GPVTF -3 DCFZ, 7 NZVS, 5 HKGWZ, 10 PSHF => 8 KHKGT - - - - 180697 ORE for 1 FUEL: - -2 VPVL, 7 FWMGM, 2 CXFTF, 11 MNCFX => 1 STKFG -17 NVRVD, 3 JNWZP => 8 VPVL -53 STKFG, 6 MNCFX, 46 VJHF, 81 HVMC, 68 CXFTF, 25 GNMV => 1 FUEL -22 VJHF, 37 MNCFX => 5 FWMGM -139 ORE => 4 NVRVD -144 ORE => 7 JNWZP -5 MNCFX, 7 RFSQX, 2 FWMGM, 2 VPVL, 19 CXFTF => 3 HVMC -5 VJHF, 7 MNCFX, 9 VPVL, 37 CXFTF => 6 GNMV -145 ORE => 6 MNCFX -1 NVRVD => 8 CXFTF -1 VJHF, 6 MNCFX => 4 RFSQX -176 ORE => 6 VJHF - - - - 2210736 ORE for 1 FUEL: - -171 ORE => 8 CNZTR -7 ZLQW, 3 BMBT, 9 XCVML, 26 XMNCP, 1 WPTQ, 2 MZWV, 1 RJRHP => 4 PLWSL -114 ORE => 4 BHXH -14 VRPVC => 6 BMBT -6 BHXH, 18 KTJDG, 12 WPTQ, 7 PLWSL, 31 FHTLT, 37 ZDVW => 1 FUEL -6 WPTQ, 2 BMBT, 8 ZLQW, 18 KTJDG, 1 XMNCP, 6 MZWV, 1 RJRHP => 6 FHTLT -15 XDBXC, 2 LTCX, 1 VRPVC => 6 ZLQW -13 WPTQ, 10 LTCX, 3 RJRHP, 14 XMNCP, 2 MZWV, 1 ZLQW => 1 ZDVW -5 BMBT => 4 WPTQ -189 ORE => 9 KTJDG -1 MZWV, 17 XDBXC, 3 XCVML => 2 XMNCP -12 VRPVC, 27 CNZTR => 2 XDBXC -15 KTJDG, 12 BHXH => 5 XCVML -3 BHXH, 2 VRPVC => 7 MZWV -121 ORE => 7 VRPVC -7 XCVML => 6 RJRHP -5 BHXH, 4 VRPVC => 5 LTCX - - - -Given the list of reactions in your puzzle input, what is the minimum amount of ORE required to -produce exactly 1 FUEL? +Given 1 trillion ORE, what is the maximum amount of FUEL you can produce? diff --git a/15/part1 b/15/part1 @@ -6,7 +6,7 @@ failed! According to the readouts, the oxygen system must have failed days ago after a rupture in oxygen tank two; that section of the ship was automatically sealed once oxygen levels went dangerously low. -A single remotely-operated repair droid is your only option for fixing the oxygen system. +A single remotely-operated repair droid is your only option for fixing the oxygen system. The Elves' care package included an Intcode program (your puzzle input) that you can use to remotely control the repair droid. By running that program, you can direct the repair droid to the oxygen @@ -15,21 +15,21 @@ system and fix the problem. The remote control program executes the following steps in a loop forever: - - Accept a movement command via an input instruction. + - Accept a movement command via an input instruction. - Send the movement command to the repair droid. - Wait for the repair droid to finish the movement operation. - - Report on the status of the repair droid via an output instruction. + - Report on the status of the repair droid via an output instruction. -Only four movement commands are understood: north (1), south (2), west (3), and east (4). Any other +Only four movement commands are understood: north (1), south (2), west (3), and east (4). Any other command is invalid. The movements differ in direction, but not in distance: in a long enough east-west hallway, a series of commands like 4,4,4,4,3,3,3,3 would leave the repair droid back where it started. -The repair droid can reply with any of the following status codes: +The repair droid can reply with any of the following status codes: - 0: The repair droid hit a wall. Its position has not changed. @@ -95,10 +95,10 @@ of 0, and then west (3) gets a reply of 2: D.# # -Now, because of the reply of 2, you know you've found the oxygen system! In this example, it was -only 2 moves away from the repair droid's starting position. +Now, because of the reply of 2, you know you've found the oxygen system! In this example, it was +only 2 moves away from the repair droid's starting position. -What is the fewest number of movement commands required to move the repair droid from its starting +What is the fewest number of movement commands required to move the repair droid from its starting position to the location of the oxygen system? diff --git a/15/part2 b/15/part2 @@ -2,9 +2,9 @@ You quickly repair the oxygen system; oxygen gradually fills the area. -Oxygen starts in the location containing the repaired oxygen system. It takes one minute for oxygen +Oxygen starts in the location containing the repaired oxygen system. It takes one minute for oxygen to spread to all open locations that are adjacent to a location that already contains oxygen. -Diagonal locations are not adjacent. +Diagonal locations are not adjacent. In the example above, suppose you've used the droid to explore the area fully and have the following map (where locations that currently contain oxygen are marked O): @@ -49,9 +49,9 @@ And finally, the whole region is full of oxygen after a total of four minutes: #OOO# ### -So, in this example, all locations contain oxygen after 4 minutes. +So, in this example, all locations contain oxygen after 4 minutes. -Use the repair droid to get a complete map of the area. How many minutes will it take to fill with -oxygen? +Use the repair droid to get a complete map of the area. How many minutes will it take to fill with +oxygen? diff --git a/16/part1 b/16/part1 @@ -2,24 +2,24 @@ You're 3/4ths of the way through the gas giants. Not only do roundtrip signals to Earth take five hours, but the signal quality is quite bad as well. You can clean up the signal with the Flawed -Frequency Transmission algorithm, or FFT. +Frequency Transmission algorithm, or FFT. As input, FFT takes a list of numbers. In the signal you received (your puzzle input), each number is a single digit: data like 15243 represents the sequence 1, 5, 2, 4, 3. -FFT operates in repeated phases. In each phase, a new list is constructed with the same length as +FFT operates in repeated phases. In each phase, a new list is constructed with the same length as the input list. This new list is also used as the input for the next phase. Each element in the new list is built by multiplying every value in the input list by a value in a -repeating pattern and then adding up the results. So, if the input list were 9, 8, 7, 6, 5 and the +repeating pattern and then adding up the results. So, if the input list were 9, 8, 7, 6, 5 and the pattern for a given element were 1, 2, 3, the result would be 9*1 + 8*2 + 7*3 + 6*1 + 5*2 (with each input element on the left and each value in the repeating pattern on the right of each multiplication). Then, only the ones digit is kept: 38 becomes 8, -17 becomes 7, and so on. While each element in the output array uses all of the same input array elements, the actual -repeating pattern to use depends on which output element is being calculated. The base pattern is 0, -1, 0, -1. Then, repeat each value in the pattern a number of times equal to the position in the -output list being considered. Repeat once for the first element, twice for the second element, three +repeating pattern to use depends on which output element is being calculated. The base pattern is 0, +1, 0, -1. Then, repeat each value in the pattern a number of times equal to the position in the +output list being considered. Repeat once for the first element, twice for the second element, three times for the third element, and so on. So, if the third element of the output list is being calculated, repeating the values would produce: 0, 0, 0, 1, 1, 1, 0, 0, 0, -1, -1, -1. @@ -90,6 +90,6 @@ Here are the first eight digits of the final output list after 100 phases for so - 69317163492948606335995924319873 becomes 52432133. -After 100 phases of FFT, what are the first eight digits in the final output list? +After 100 phases of FFT, what are the first eight digits in the final output list? diff --git a/16/part2 b/16/part2 @@ -1,13 +1,13 @@ --- Part Two --- -Now that your FFT is working, you can decode the real signal. +Now that your FFT is working, you can decode the real signal. -The real signal is your puzzle input repeated 10000 times. Treat this new signal as a single input +The real signal is your puzzle input repeated 10000 times. Treat this new signal as a single input list. Patterns are still calculated as before, and 100 phases of FFT are still applied. -The first seven digits of your initial input signal also represent the message offset. The message +The first seven digits of your initial input signal also represent the message offset. The message offset is the location of the eight-digit message in the final output list. Specifically, the -message offset indicates the number of digits to skip before reading the eight-digit message. For +message offset indicates the number of digits to skip before reading the eight-digit message. For example, if the first seven digits of your initial input signal were 1234567, the eight-digit message would be the eight digits after skipping 1,234,567 digits of the final output list. Or, if the message offset were 7 and your final output list were 98765432109876543210, the eight-digit @@ -19,14 +19,14 @@ in each input has been highlighted. (Note that the inputs given below are repeat find the actual starting input lists.) - - 03036732577212944063491565474664 becomes 84462026. + - 03036732577212944063491565474664 becomes 84462026. - - 02935109699940807407585447034323 becomes 78725270. + - 02935109699940807407585447034323 becomes 78725270. - - 03081770884921959731165446850517 becomes 53553731. + - 03081770884921959731165446850517 becomes 53553731. -After repeating your input signal 10000 times and running 100 phases of FFT, what is the eight-digit -message embedded in the final output list? +After repeating your input signal 10000 times and running 100 phases of FFT, what is the eight-digit +message embedded in the final output list? diff --git a/17/part1 b/17/part1 @@ -9,7 +9,7 @@ The only tools at your disposal are some wired cameras and a small vacuum robot 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 +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. @@ -19,8 +19,8 @@ of output below the current one, and so on. (Within a line, characters are drawn 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. +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: @@ -37,8 +37,8 @@ Here, the vacuum robot, ^ is facing up and sitting at one end of the scaffold ne 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 +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: @@ -54,20 +54,20 @@ 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. +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. +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. +is 24. - - The bottom-right intersection's alignment parameter is 40. + - 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. +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? +Run your ASCII program. What is the sum of the alignment parameters for the scaffold intersections? diff --git a/17/part2 b/17/part2 @@ -2,36 +2,36 @@ Now for the tricky part: notifying all the other robots about the solar flare. The vacuum robot can do this automatically if it gets into range of a robot. However, you can't see the other robots on -the camera, so you need to be thorough instead: you need to make the vacuum robot visit every part -of the scaffold at least once. +the camera, so you need to be thorough instead: you need to make the vacuum robot visit every part +of the scaffold at least once. The vacuum robot normally wanders randomly, but there isn't time for that today. Instead, you can -override its movement logic with new rules. +override its movement logic with new rules. Force the vacuum robot to wake up by changing the value in your ASCII program at address 0 from 1 to -2. When you do this, you will be automatically prompted for the new movement rules that the vacuum +2. When you do this, you will be automatically prompted for the new movement rules that the vacuum robot should use. The ASCII program will use input instructions to receive them, but they need to be provided as ASCII code; end each line of logic with a single newline, ASCII code 10. -First, you will be prompted for the main movement routine. The main routine may only call the -movement functions: A, B, or C. Supply the movement functions to use as ASCII text, separating them +First, you will be prompted for the main movement routine. The main routine may only call the +movement functions: A, B, or C. Supply the movement functions to use as ASCII text, separating them with commas (,, ASCII code 44), and ending the list with a newline (ASCII code 10). For example, to call A twice, then alternate between B and C three times, provide the string A,A,B,C,B,C,B,C and then a newline. -Then, you will be prompted for each movement function. Movement functions may use L to turn left, R -to turn right, or a number to move forward that many units. Movement functions may not call other -movement functions. Again, separate the actions with commas and end the list with a newline. For -example, to move forward 10 units, turn left, move forward 8 units, turn right, and finally move +Then, you will be prompted for each movement function. Movement functions may use L to turn +left, R to turn right, or a number to move forward that many units. Movement functions may not call +other movement functions. Again, separate the actions with commas and end the list with a newline. +For example, to move forward 10 units, turn left, move forward 8 units, turn right, and finally move forward 6 units, provide the string 10,L,8,R,6 and then a newline. -Finally, you will be asked whether you want to see a continuous video feed; provide either y or n +Finally, you will be asked whether you want to see a continuous video feed; provide either y or n and a newline. Enabling the continuous video feed can help you see what's going on, but it also requires a significant amount of processing power, and may even cause your Intcode computer to overheat. Due to the limited amount of memory in the vacuum robot, the ASCII definitions of the main routine -and the movement functions may each contain at most 20 characters, not counting the newline. +and the movement functions may each contain at most 20 characters, not counting the newline. For example, consider the following camera feed: @@ -51,7 +51,7 @@ For example, consider the following camera feed: ....#...#...... ....#####...... -In order for the vacuum robot to visit every part of the scaffold at least once, one path it could +In order for the vacuum robot to visit every part of the scaffold at least once, one path it could take is: R,8,R,8,R,4,R,4,R,8,L,6,L,2,R,4,R,4,R,8,R,8,R,8,L,6,L,2 @@ -61,13 +61,13 @@ routine call A once. However, you'll need to split it into smaller parts. One approach is: - - Main routine: A,B,C,B,A,C(ASCII input: 65, 44, 66, 44, 67, 44, 66, 44, 65, 44, 67, 10) + - Main routine: A,B,C,B,A,C(ASCII input: 65, 44, 66, 44, 67, 44, 66, 44, 65, 44, 67, 10) - - Function A:   R,8,R,8(ASCII input: 82, 44, 56, 44, 82, 44, 56, 10) + - Function A:   R,8,R,8(ASCII input: 82, 44, 56, 44, 82, 44, 56, 10) - - Function B:   R,4,R,4,R,8(ASCII input: 82, 44, 52, 44, 82, 44, 52, 44, 82, 44, 56, 10) + - Function B:   R,4,R,4,R,8(ASCII input: 82, 44, 52, 44, 82, 44, 52, 44, 82, 44, 56, 10) - - Function C:   L,6,L,2(ASCII input: 76, 44, 54, 44, 76, 44, 50, 10) + - Function C:   L,6,L,2(ASCII input: 76, 44, 54, 44, 76, 44, 50, 10) Visually, this would break the desired path into the following parts: @@ -99,7 +99,7 @@ programmed set of movements, assuming it hasn't drifted off into space, the clea return to its docking station and report the amount of space dust it collected as a large, non-ASCII value in a single output instruction. -After visiting every part of the scaffold at least once, how much dust does the vacuum robot report -it has collected? +After visiting every part of the scaffold at least once, how much dust does the vacuum robot report +it has collected? diff --git a/18/part1 b/18/part1 @@ -6,11 +6,11 @@ on Triton! You have no choice but to land. A scan of the local area reveals only one interesting feature: a massive underground vault. You generate a map of the tunnels (your puzzle input). The tunnels are too narrow to move diagonally. -Only one entrance (marked @) is present among the open passages (marked .) and stone walls (#), but -you also detect an assortment of keys (shown as lowercase letters) and doors (shown as uppercase +Only one entrance (marked @) is present among the open passages (marked .) and stone walls (#), but +you also detect an assortment of keys (shown as lowercase letters) and doors (shown as uppercase letters). Keys of a given letter open the door of the same letter: a opens A, b opens B, and so on. -You aren't sure which key you need to disable the tractor beam, so you'll need to collect all of -them. +You aren't sure which key you need to disable the tractor beam, so you'll need to collect all of +them. For example, suppose you have the following map: @@ -31,7 +31,7 @@ Then, you can move 6 steps to collect the only other key, b: #@......# ######### -So, collecting every key took a total of 8 steps. +So, collecting every key took a total of 8 steps. Here is a larger example: @@ -74,7 +74,7 @@ slower in the long run than collecting key d first, so that's the best choice: #@.....................# ######################## -Finally, collect key e to unlock door E, then collect key f, taking a grand total of 86 steps. +Finally, collect key e to unlock door E, then collect key f, taking a grand total of 86 steps. Here are a few more examples: @@ -112,6 +112,6 @@ Shortest paths are 81 steps; one is: a, c, f, i, d, g, b, e, h -How many steps is the shortest path that collects all of the keys? +How many steps is the shortest path that collects all of the keys? diff --git a/18/part2 b/18/part2 @@ -1,6 +1,6 @@ --- Part Two --- -You arrive at the vault only to discover that there is not one vault, but four - each with its own +You arrive at the vault only to discover that there is not one vault, but four - each with its own entrance. On your map, find the area in the middle that looks like this: @@ -19,9 +19,9 @@ This change will split your map into four separate sections, each with its own e ####### ####### #a.#Cd# #a.#Cd# -##...## ##@#@## -##.@.## --> ####### -##...## ##@#@## +##...## ##@#@## +##.@.## --> ####### +##...## ##@#@## #cB#Ab# #cB#Ab# ####### ####### @@ -29,7 +29,7 @@ Because some of the keys are for doors in other vaults, it would take much too l of the keys by yourself. Instead, you deploy four remote-controlled robots. Each starts at one of the entrances (@). -Your goal is still to collect all of the keys in the fewest steps, but now, each robot has its own +Your goal is still to collect all of the keys in the fewest steps, but now, each robot has its own position and can move independently. You can only remotely control a single robot at a time. Collecting a key instantly unlocks any corresponding doors, regardless of the vault in which the key or door is found. @@ -75,7 +75,7 @@ Finally, the top-right robot collects key d: #@.#.@# ####### -In this example, it only took 8 steps to collect all of the keys. +In this example, it only took 8 steps to collect all of the keys. Sometimes, multiple robots might have keys available, or a robot might have to wait for multiple keys to be collected: @@ -90,7 +90,7 @@ keys to be collected: First, the top-right, bottom-left, and bottom-right robots take turns collecting keys a, b, and c, a total of 6 + 6 + 6 = 18 steps. Then, the top-left robot can access key d, spending another 6 steps; -collecting all of the keys here takes a minimum of 24 steps. +collecting all of the keys here takes a minimum of 24 steps. Here's a more complex example: @@ -128,7 +128,7 @@ Here's a more complex example: - Top-right robot collects key l. -In the above example, the fewest steps to collect all of the keys is 32. +In the above example, the fewest steps to collect all of the keys is 32. Here's an example with more choices: @@ -176,9 +176,9 @@ One solution with the fewest steps is: - Bottom-left robot collects key o. -This example requires at least 72 steps to collect all keys. +This example requires at least 72 steps to collect all keys. -After updating your map and using the remote-controlled robots, what is the fewest steps necessary -to collect all of the keys? +After updating your map and using the remote-controlled robots, what is the fewest steps necessary +to collect all of the keys? diff --git a/19/part1 b/19/part1 @@ -9,15 +9,15 @@ drone system can be configured to deploy a drone to specific coordinates and the being pulled. There's even an Intcode program (your puzzle input) that gives you access to the drone system. -The program uses two input instructions to request the X and Y position to which the drone should be -deployed. Negative numbers are invalid and will confuse the drone; all numbers should be zero or -positive. +The program uses two input instructions to request the X and Y position to which the drone should be +deployed. Negative numbers are invalid and will confuse the drone; all numbers should be +zero or positive. -Then, the program will output whether the drone is stationary (0) or being pulled by something (1). +Then, the program will output whether the drone is stationary (0) or being pulled by something (1). For example, the coordinate X=0, Y=0 is directly in front of the tractor beam emitter, so the drone control program will always report 1 at that location. -To better understand the tractor beam, it is important to get a good picture of the beam itself. For +To better understand the tractor beam, it is important to get a good picture of the beam itself. For example, suppose you scan the 10x10 grid of points closest to the emitter: X @@ -33,11 +33,11 @@ Y .....####. .......### 9........## -In this example, the number of points affected by the tractor beam in the 10x10 area closest to the -emitter is 27. +In this example, the number of points affected by the tractor beam in the 10x10 area closest to the +emitter is 27. -However, you'll need to scan a larger area to understand the shape of the beam. How many points are -affected by the tractor beam in the 50x50 area closest to the emitter? (For each of X and Y, this +However, you'll need to scan a larger area to understand the shape of the beam. How many points are +affected by the tractor beam in the 50x50 area closest to the emitter? (For each of X and Y, this will be 0 through 49.) diff --git a/19/part2 b/19/part2 @@ -1,8 +1,8 @@ --- Part Two --- You aren't sure how large Santa's ship is. You aren't even sure if you'll need to use this thing on -Santa's ship, but it doesn't hurt to be prepared. You figure Santa's ship might fit in a 100x100 -square. +Santa's ship, but it doesn't hurt to be prepared. You figure Santa's ship might fit in a +100x100 square. The beam gets wider as it travels away from the emitter; you'll need to be a minimum distance away to fit a square of that size into the beam fully. (Don't rotate the square; it should be aligned to @@ -30,7 +30,7 @@ For example, suppose you have the following tractor beam readings: ...............###############.......... ................###############......... ................#################....... -.................########OOOOOOOOOO..... +.................########OOOOOOOOOO..... ..................#######OOOOOOOOOO#.... ...................######OOOOOOOOOO###.. ....................#####OOOOOOOOOO##### @@ -46,13 +46,13 @@ For example, suppose you have the following tractor beam readings: ............................############ .............................########### -In this example, the 10x10 square closest to the emitter that fits entirely within the tractor beam -has been marked O. Within it, the point closest to the emitter (the only highlighted O) is at X=25, +In this example, the 10x10 square closest to the emitter that fits entirely within the tractor beam +has been marked O. Within it, the point closest to the emitter (the only highlighted O) is at X=25, Y=20. -Find the 100x100 square closest to the emitter that fits entirely within the tractor beam; within -that square, find the point closest to the emitter. What value do you get if you take that point's -X coordinate, multiply it by 10000, then add the point's Y coordinate? (In the example above, this +Find the 100x100 square closest to the emitter that fits entirely within the tractor beam; within +that square, find the point closest to the emitter. What value do you get if you take that point's +X coordinate, multiply it by 10000, then add the point's Y coordinate? (In the example above, this would be 250020.) diff --git a/20/part1 b/20/part1 @@ -43,7 +43,7 @@ One path through the maze doesn't require any portals. Starting at AA, you coul However, there is a shorter path: You could walk from AA to the inner BC portal (4 steps), warp to the outer BC portal (1 step), walk to the inner DE (6 steps), warp to the outer DE (1 step), walk to the outer FG (4 steps), warp to the inner FG (1 step), and finally walk to ZZ (6 steps). In total, -this is only 23 steps. +this is only 23 steps. Here is a larger example: @@ -86,9 +86,9 @@ YN......# VT..#....QG U P P Here, AA has no direct path to ZZ, but it does connect to AS and CP. By passing through AS, QG, BU, -and JO, you can reach ZZ in 58 steps. +and JO, you can reach ZZ in 58 steps. -In your maze, how many steps does it take to get from the open tile marked AA to the open tile -marked ZZ? +In your maze, how many steps does it take to get from the open tile marked AA to the open tile +marked ZZ? diff --git a/20/part2 b/20/part2 @@ -1,12 +1,12 @@ --- Part Two --- Strangely, the exit isn't open when you reach it. Then, you remember: the ancient Plutonians were -famous for building recursive spaces. +famous for building recursive spaces. -The marked connections in the maze aren't portals: they physically connect to a larger or smaller +The marked connections in the maze aren't portals: they physically connect to a larger or smaller copy of the maze. Specifically, the labeled tiles around the inside edge actually connect to a -smaller copy of the same maze, and the smaller copy's inner labeled tiles connect to yet a smaller -copy, and so on. +smaller copy of the same maze, and the smaller copy's inner labeled tiles connect to yet a +smaller copy, and so on. When you enter the maze, you are at the outermost level; when at the outermost level, only the outer labels AA and ZZ function (as the start and end, respectively); all other outer labeled tiles are @@ -198,10 +198,10 @@ One shortest path through the maze is the following: - Walk from FD to ZZ (18 steps) -This path takes a total of 396 steps to move from AA at the outermost layer to ZZ at the outermost +This path takes a total of 396 steps to move from AA at the outermost layer to ZZ at the outermost layer. -In your maze, when accounting for recursion, how many steps does it take to get from the open tile -marked AA to the open tile marked ZZ, both at the outermost layer? +In your maze, when accounting for recursion, how many steps does it take to get from the open tile +marked AA to the open tile marked ZZ, both at the outermost layer? diff --git a/21/part1 b/21/part1 @@ -9,42 +9,43 @@ 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 jump over the holes in the hull - a -springdroid. +The clear choice for this mission is a droid that can jump over the holes in the hull - a +springdroid. 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 springscript. +language called springscript. While a springdroid is certainly capable of navigating the artificial gravity and giant holes, it -has one downside: it can only remember at most 15 springscript instructions. +has one downside: it can only remember at most 15 springscript instructions. -The springdroid will move forward automatically, constantly thinking about whether to jump. The +The springdroid will move forward automatically, constantly thinking about whether to jump. 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 temporary value register, and J, the jump register. If the jump register is true at the end -of the springscript program, the springdroid will try to jump. Both of these registers start with -the value false. +T, the temporary value register, and J, the jump register. If the jump register is +true at the end of the springscript program, the springdroid will try to jump. Both of these +registers start with the value false. -Springdroids have a sensor that can detect whether there is ground at various distances in the -direction it is facing; these values are provided in read-only registers. Your springdroid can +Springdroids have a sensor that can detect whether there is ground at various distances in the +direction it is facing; these values are provided in read-only registers. 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 true; if there -is a hole, the register will be false. +four tiles away (D). If there is ground at the given distance, the register will be +true; if there is a hole, the register will be false. -There are only three instructions available in springscript: +There are only three instructions available in springscript: - - AND X Y sets Y to true if both X and Y are true; otherwise, it sets Y to false. + - AND X Y sets Y to true if both X and Y are true; otherwise, it sets Y to false. - - OR X Y sets Y to true if at least one of X or Y is true; otherwise, it sets Y to false. + - OR X Y sets Y to true if at least one of X or Y is true; otherwise, it sets Y to +false. - - NOT X Y sets Y to true if X is false; otherwise, it sets Y to false. + - NOT X Y sets Y to true if X is false; otherwise, it sets Y to false. -In all three instructions, the second argument (Y) needs to be a writable register (either T or J). -The first argument (X) can be any register (including A, B, C, or D). +In all three instructions, the second argument (Y) needs to be a writable register (either T or J). +The first argument (X) can be any register (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". @@ -60,59 +61,59 @@ 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). When you -have finished entering your program, provide the command WALK followed by a newline to instruct the -springdroid to begin surveying the hull. +input the desired instructions one per line. End each line with a newline (ASCII code 10). +When you have finished entering your program, provide the command WALK followed by a newline to +instruct the springdroid to begin surveying the hull. -If the springdroid falls into space, an ASCII rendering of the last moments of its life will be +If the springdroid falls into space, 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 true if and only if there is no ground four tiles away. In +This one-instruction program sets J to true if and only if there is no ground four tiles away. In other words, it attempts to jump into any hole it finds: ................. ................. -@................ +@................ #####.########### ................. ................. -.@............... +.@............... #####.########### ................. -..@.............. +..@.............. ................. #####.########### -...@............. +...@............. ................. ................. #####.########### ................. -....@............ +....@............ ................. #####.########### ................. ................. -.....@........... +.....@........... #####.########### ................. ................. ................. -#####@########### +#####@########### However, if the springdroid successfully makes it across, it will use an output instruction to -indicate the amount of damage to the hull as a single giant integer outside the normal ASCII range. +indicate the amount of damage to the hull 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. -What amount of hull damage does it report? +What amount of hull damage does it report? diff --git a/21/part2 b/21/part2 @@ -1,27 +1,27 @@ --- Part Two --- There are many areas the springdroid can't reach. You flip through the manual and discover a way to -increase its sensor range. +increase its sensor range. -Instead of ending your springcode program with WALK, use RUN. Doing this will enable extended sensor -mode, capable of sensing ground up to nine tiles away. This data is available in five new read-only -registers: +Instead of ending your springcode program with WALK, use RUN. Doing this will enable +extended sensor mode, capable of sensing ground up to nine tiles away. This data is available in +five new read-only registers: - - Register E indicates whether there is ground five tiles away. + - Register E indicates whether there is ground five tiles away. - - Register F indicates whether there is ground six tiles away. + - Register F indicates whether there is ground six tiles away. - - Register G indicates whether there is ground seven tiles away. + - Register G indicates whether there is ground seven tiles away. - - Register H indicates whether there is ground eight tiles away. + - Register H indicates whether there is ground eight tiles away. - - Register I indicates whether there is ground nine tiles away. + - Register I indicates whether there is ground nine tiles away. All other functions remain the same. -Successfully survey the rest of the hull by ending your program with RUN. What amount of hull -damage does the springdroid now report? +Successfully survey the rest of the hull by ending your program with RUN. What amount of hull +damage does the springdroid now report? diff --git a/22/part1 b/22/part1 @@ -3,15 +3,15 @@ There isn't much to do while you wait for the droids to repair your ship. At least you're drifting in the right direction. You decide to practice a new card shuffle you've been working on. -Digging through the ship's storage, you find a deck of space cards! Just like any deck of space +Digging through the ship's storage, you find a deck of space cards! Just like any deck of space cards, there are 10007 cards in the deck numbered 0 through 10006. The deck must be new - they're -still in factory order, with 0 on the top, then 1, then 2, and so on, all the way through to 10006 +still in factory order, with 0 on the top, then 1, then 2, and so on, all the way through to 10006 on the bottom. -You've been practicing three different techniques that you use while shuffling. Suppose you have a +You've been practicing three different techniques that you use while shuffling. Suppose you have a deck of only 10 cards (numbered 0 through 9): -To deal into new stack, create a new stack of cards by dealing the top card of the deck onto the top +To deal into new stack, create a new stack of cards by dealing the top card of the deck onto the top of the new stack repeatedly until you run out of cards: Top Bottom @@ -37,7 +37,7 @@ Several steps later... Finally, pick up the new stack you've just created and use it as the deck for the next technique. -To cut N cards, take the top N cards off the top of the deck and move them as a single unit to the +To cut N cards, take the top N cards off the top of the deck and move them as a single unit to the bottom of the deck, retaining their order. For example, to cut 3: Top Bottom @@ -66,7 +66,7 @@ Top Bottom 6 7 8 9 0 1 2 3 4 5 Your deck -To deal with increment N, start by clearing enough space on your table to lay out all of the cards +To deal with increment N, start by clearing enough space on your table to lay out all of the cards individually in a long line. Deal the top card into the leftmost position. Then, move N positions to the right and deal the next card there. If you would move into a position past the end of the space on your table, wrap around and keep counting from the leftmost card again. Continue this @@ -128,7 +128,7 @@ the card to its right ends up just below the top card, and so on, until the righ at the bottom of the deck. The complete shuffle process (your puzzle input) consists of applying many of these techniques. -Here are some examples that combine techniques; they all start with a factory order deck of 10 +Here are some examples that combine techniques; they all start with a factory order deck of 10 cards: deal with increment 7 @@ -161,6 +161,6 @@ Result: 9 2 5 8 1 4 7 0 3 6 Positions within the deck count from 0 at the top, then 1 for the card immediately below the top card, and so on to the bottom. (That is, cards start in the position matching their number.) -After shuffling your factory order deck of 10007 cards, what is the position of card 2019? +After shuffling your factory order deck of 10007 cards, what is the position of card 2019? diff --git a/22/part2 b/22/part2 @@ -6,17 +6,17 @@ repairs. While reviewing the work the droids have finished so far, you think yo fly past! When you get back, you discover that the 3D printers have combined their power to create for you a -single, giant, brand new, factory order deck of 119315717514047 space cards. +single, giant, brand new, factory order deck of 119315717514047 space cards. Finally, a deck of cards worthy of shuffling! -You decide to apply your complete shuffle process (your puzzle input) to the deck 101741582076661 -times in a row. +You decide to apply your complete shuffle process (your puzzle input) to the deck +101741582076661 times in a row. -You'll need to be careful, though - one wrong move with this many cards and you might overflow your -entire ship! +You'll need to be careful, though - one wrong move with this many cards and you might +overflow your entire ship! -After shuffling your new, giant, factory order deck that many times, what number is on the card that -ends up in position 2020? +After shuffling your new, giant, factory order deck that many times, what number is on the card that +ends up in position 2020? diff --git a/23/part1 b/23/part1 @@ -1,28 +1,28 @@ --- Day 23: Category Six --- The droids have finished repairing as much of the ship as they can. Their report indicates that -this was a Category 6 disaster - not because it was that bad, but because it destroyed the stockpile +this was a Category 6 disaster - not because it was that bad, but because it destroyed the stockpile of Category 6 network cables as well as most of the ship's network infrastructure. -You'll need to rebuild the network from scratch. +You'll need to rebuild the network from scratch. -The computers on the network are standard Intcode computers that communicate by sending packets to -each other. There are 50 of them in total, each running a copy of the same Network Interface -Controller (NIC) software (your puzzle input). The computers have network addresses 0 through 49; -when each computer boots up, it will request its network address via a single input instruction. Be -sure to give each computer a unique network address. +The computers on the network are standard Intcode computers that communicate by sending +packets to each other. There are 50 of them in total, each running a copy of the same +Network Interface Controller (NIC) software (your puzzle input). The computers have network +addresses 0 through 49; when each computer boots up, it will request its network address via a +single input instruction. Be sure to give each computer a unique network address. Once a computer has received its network address, it will begin doing work and communicating over -the network by sending and receiving packets. All packets contain two values named X and Y. Packets +the network by sending and receiving packets. All packets contain two values named X and Y. Packets sent to a computer are queued by the recipient and read in the order they are received. -To send a packet to another computer, the NIC will use three output instructions that provide the -destination address of the packet followed by its X and Y values. For example, three output +To send a packet to another computer, the NIC will use three output instructions that provide the +destination address of the packet followed by its X and Y values. For example, three output instructions that provide the values 10, 20, 30 would send a packet with X=20 and Y=30 to the computer with address 10. -To receive a packet from another computer, the NIC will use an input instruction. If the incoming -packet queue is empty, provide -1. Otherwise, provide the X value of the next packet; the computer +To receive a packet from another computer, the NIC will use an input instruction. If the incoming +packet queue is empty, provide -1. Otherwise, provide the X value of the next packet; the computer will then use a second input instruction to receive the Y value for the same packet. Once both values of the packet are read in this way, the packet is removed from the queue. @@ -31,7 +31,7 @@ wait for the sent packet to be received - the computer might send multiple packe any. Similarly, input instructions do not wait for a packet to arrive - if no packet is waiting, input instructions should receive -1. -Boot up all 50 computers and attach them to your network. What is the Y value of the first packet -sent to address 255? +Boot up all 50 computers and attach them to your network. What is the Y value of the first packet +sent to address 255? diff --git a/23/part2 b/23/part2 @@ -5,18 +5,18 @@ is responsible for managing power consumption of the network by blocking certain watching for idle periods in the computers. If a packet would be sent to address 255, the NAT receives it instead. The NAT remembers only the -last packet it receives; that is, the data in each packet it receives overwrites the NAT's packet +last packet it receives; that is, the data in each packet it receives overwrites the NAT's packet memory with the new packet's X and Y values. -The NAT also monitors all computers on the network. If all computers have empty incoming packet -queues and are continuously trying to receive packets without sending packets, the network is -considered idle. +The NAT also monitors all computers on the network. If all computers have empty incoming packet +queues and are continuously trying to receive packets without sending packets, the network is +considered idle. -Once the network is idle, the NAT sends only the last packet it received to address 0; this will +Once the network is idle, the NAT sends only the last packet it received to address 0; this will cause the computers on the network to resume activity. In this way, the NAT can throttle power consumption of the network when the ship needs power in other areas. -Monitor packets released to the computer at address 0 by the NAT. What is the first Y value -delivered by the NAT to the computer at address 0 twice in a row? +Monitor packets released to the computer at address 0 by the NAT. What is the first Y value +delivered by the NAT to the computer at address 0 twice in a row? diff --git a/24/part1 b/24/part1 @@ -5,19 +5,19 @@ picking up strange life forms moving around: Eris is infested with bugs! With an roundtrip for messages between you and Earth, you'll have to deal with this problem on your own. Eris isn't a very large place; a scan of the entire area fits into a 5x5 grid (your puzzle input). -The scan shows bugs (#) and empty spaces (.). +The scan shows bugs (#) and empty spaces (.). -Each minute, The bugs live and die based on the number of bugs in the four adjacent tiles: +Each minute, The bugs live and die based on the number of bugs in the four adjacent tiles: - - A bug dies (becoming an empty space) unless there is exactly one bug adjacent to it. + - A bug dies (becoming an empty space) unless there is exactly one bug adjacent to it. - - An empty space becomes infested with a bug if exactly one or two bugs are adjacent to it. + - An empty space becomes infested with a bug if exactly one or two bugs are adjacent to it. Otherwise, a bug or empty space remains the same. (Tiles on the edges of the grid have fewer than four adjacent tiles; the missing tiles count as empty space.) This process happens in every location -simultaneously; that is, within the same minute, the number of adjacent bugs is counted for every +simultaneously; that is, within the same minute, the number of adjacent bugs is counted for every tile first, and then the tiles are updated. Here are the first few minutes of an example scenario: @@ -58,7 +58,7 @@ After 4 minutes: ##... To understand the nature of the bugs, watch for the first time a layout of bugs and empty spaces -matches any previous layout. In the example above, the first layout to appear twice is: +matches any previous layout. In the example above, the first layout to appear twice is: ..... ..... @@ -66,12 +66,12 @@ matches any previous layout. In the example above, the first layout to appear tw #.... .#... -To calculate the biodiversity rating for this layout, consider each tile left-to-right in the top +To calculate the biodiversity rating for this layout, consider each tile left-to-right in the top row, then left-to-right in the second row, and so on. Each of these tiles is worth biodiversity -points equal to increasing powers of two: 1, 2, 4, 8, 16, 32, and so on. Add up the biodiversity +points equal to increasing powers of two: 1, 2, 4, 8, 16, 32, and so on. Add up the biodiversity points for tiles with bugs; in this example, the 16th tile (32768 points) and 22nd tile (2097152 -points) have bugs, a total biodiversity rating of 2129920. +points) have bugs, a total biodiversity rating of 2129920. -What is the biodiversity rating for the first layout that appears twice? +What is the biodiversity rating for the first layout that appears twice? diff --git a/24/part2 b/24/part2 @@ -1,11 +1,12 @@ --- Part Two --- -After careful analysis, one thing is certain: you have no idea where all these bugs are coming from. +After careful analysis, one thing is certain: you have no idea where all these bugs are coming +from. Then, you remember: Eris is an old Plutonian settlement! Clearly, the bugs are coming from recursively-folded space. -This 5x5 grid is only one level in an infinite number of recursion levels. The tile in the middle of +This 5x5 grid is only one level in an infinite number of recursion levels. The tile in the middle of the grid is actually another 5x5 grid, the grid in your scan is contained as the middle tile of a larger 5x5 grid, and so on. Two levels of grids look like this: @@ -40,11 +41,11 @@ the infinitely recursive grid; there is a 5x5 grid that contains this diagram, a contains that one, and so on. Also, the ? in the diagram contains another 5x5 grid, which itself contains another 5x5 grid, and so on. -The scan you took (your puzzle input) shows where the bugs are on a single level of this structure. +The scan you took (your puzzle input) shows where the bugs are on a single level of this structure. The middle tile of your scan is empty to accommodate the recursive grids within it. Initially, no other levels contain bugs. -Tiles still count as adjacent if they are directly up, down, left, or right of a given tile. Some +Tiles still count as adjacent if they are directly up, down, left, or right of a given tile. Some tiles have adjacent tiles at a recursion level above or below its own level. For example: | | | | @@ -82,9 +83,9 @@ tiles have adjacent tiles at a recursion level above or below its own level. For - Tile E has four adjacent tiles: 8, D, 14, and J. - - Tile 14 has eight adjacent tiles: 9, E, J, O, T, Y, 15, and 19. + - Tile 14 has eight adjacent tiles: 9, E, J, O, T, Y, 15, and 19. - - Tile N has eight adjacent tiles: I, O, S, and five tiles within the sub-grid marked ?. + - Tile N has eight adjacent tiles: I, O, S, and five tiles within the sub-grid marked ?. The rules about bugs living and dying are the same as before. @@ -98,8 +99,8 @@ For example, consider the same initial state as above: #.... The center tile is drawn as ? to indicate the next recursive grid. Call this level 0; the grid -within this one is level 1, and the grid that contains this one is level -1. Then, after ten -minutes, the grid at each level would look like this: +within this one is level 1, and the grid that contains this one is level -1. Then, after +ten minutes, the grid at each level would look like this: Depth -5: ..#.. @@ -178,8 +179,8 @@ Depth 5: ####. ..... -In this example, after 10 minutes, a total of 99 bugs are present. +In this example, after 10 minutes, a total of 99 bugs are present. -Starting with your scan, how many bugs are present after 200 minutes? +Starting with your scan, how many bugs are present after 200 minutes? diff --git a/25/main.c b/25/main.c @@ -522,6 +522,12 @@ exit: } hmap_deinit(&map); + for (HMAP_ITER(&states, &iter)) { + free(iter.link->key._p); + free(iter.link->value._p); + } + hmap_deinit(&states); + for (DVEC_ITER(&items, name)) free(*name); dvec_deinit(&items); diff --git a/25/part1 b/25/part1 @@ -19,25 +19,25 @@ Command?, you can give it a single instruction terminated with a newline (ASCII instructions are: - - Movement via north, south, east, or west. + - Movement via north, south, east, or west. - - To take an item the droid sees in the environment, use the command take <name of item>. For + - To take an item the droid sees in the environment, use the command take <name of item>. For example, if the droid reports seeing a red ball, you can pick it up with take red ball. - - To drop an item the droid is carrying, use the command drop <name of item>. For example, if the + - To drop an item the droid is carrying, use the command drop <name of item>. For example, if the droid is carrying a green ball, you can drop it with drop green ball. - - To get a list of all of the items the droid is currently carrying, use the command inv (for + - To get a list of all of the items the droid is currently carrying, use the command inv (for "inventory"). Extra spaces or other characters aren't allowed - instructions must be provided precisely. -Santa's ship is a Reindeer-class starship; these ships use pressure-sensitive floors to determine +Santa's ship is a Reindeer-class starship; these ships use pressure-sensitive floors to determine the identity of droids and crew members. The standard configuration for these starships is for all droids to weigh exactly the same amount to make them easier to detect. If you need to get past such a sensor, you might be able to reach the correct weight by carrying items from the environment. -Look around the ship and see if you can find the password for the main airlock. +Look around the ship and see if you can find the password for the main airlock. diff --git a/25/part2 b/25/part2 @@ -5,7 +5,7 @@ levels. Santa explains that he didn't notice you coming because he was just tak The ship wasn't frozen; he just had the thermostat set to "North Pole". You make your way over to the navigation console. It beeps. "Status: Stranded. Please supply -measurements from 49 stars to recalibrate." +measurements from 49 stars to recalibrate." "49 stars? But the Elves told me you needed fifty--" diff --git a/common/aoc.h b/common/aoc.h @@ -13,7 +13,8 @@ struct aoc { char *input; size_t input_size; - const char **args; + int argc; + const char **argv; }; extern struct aoc aoc; diff --git a/common/main.c b/common/main.c @@ -17,7 +17,8 @@ main(int argc, const char **argv) } aoc.part = atoi(argv[1]); - aoc.args = &argv[2]; + aoc.argc = argc - 2; + aoc.argv = &argv[2]; envvar = getenv("AOC_DEBUG"); aoc.debug = envvar ? atoi(envvar) : 0; diff --git a/lib/libpq b/lib/libpq @@ -1 +0,0 @@ -Subproject commit 46465417e54567584f6d26c157e7ae345e01088e