diff --git a/code/random/randomAlgos/google-graph-from-chris.js b/code/random/randomAlgos/google-graph-from-chris.js deleted file mode 100644 index 7529f37..0000000 --- a/code/random/randomAlgos/google-graph-from-chris.js +++ /dev/null @@ -1,156 +0,0 @@ -var $_$c = $_$wp(1); -const cave = ($_$w(1, 0, $_$c), [ - [ - [ - { - blocked: false, - treasure: false - }, - { - blocked: false, - treasure: true - } - ], - [ - { - blocked: false, - treasure: true - }, - { - blocked: false, - treasure: false - } - ] - ], - [ - [ - { - blocked: false, - treasure: false - }, - { - blocked: false, - treasure: false - } - ], - [ - { - blocked: false, - treasure: true - }, - { - blocked: false, - treasure: false - } - ] - ] -]); -function Submersible(caveInput, startingX, startingY, startingZ) { - var $_$c = $_$wf(1); - $_$w(1, 1, $_$c), this.cave = caveInput; - $_$w(1, 2, $_$c), this.x = startingX; - $_$w(1, 3, $_$c), this.y = startingY; - $_$w(1, 4, $_$c), this.z = startingZ; - $_$w(1, 5, $_$c), this.treasuresFound = []; - $_$w(1, 6, $_$c), this.currentPath = []; -} -$_$w(1, 7, $_$c), Submersible.prototype.scan = function scan() { - var $_$c = $_$wf(1); - const validDirections = ($_$w(1, 8, $_$c), []); - const dx = ($_$w(1, 9, $_$c), [ - 0, - 0, - 0, - 0, - 1, - -1 - ]); - const dy = ($_$w(1, 10, $_$c), [ - 0, - 0, - 1, - -1, - 0, - 0 - ]); - const dz = ($_$w(1, 11, $_$c), [ - 1, - -1, - 0, - 0, - 0, - 0 - ]); - for (let i = 0; $_$w(1, 12, $_$c), i < 6; i++) { - const newX = ($_$w(1, 13, $_$c), this.x + dx[i]); - const newY = ($_$w(1, 14, $_$c), this.y + dy[i]); - const newZ = ($_$w(1, 15, $_$c), this.z + dz[i]); - if ($_$w(1, 16, $_$c), ($_$w(1, 17, $_$c), ($_$w(1, 19, $_$c), ($_$w(1, 21, $_$c), ($_$w(1, 23, $_$c), ($_$w(1, 25, $_$c), newX >= 0) && ($_$w(1, 26, $_$c), newY >= 0)) && ($_$w(1, 24, $_$c), newZ >= 0)) && ($_$w(1, 22, $_$c), newX < this.cave.length)) && ($_$w(1, 20, $_$c), newY < this.cave[0].length)) && ($_$w(1, 18, $_$c), newZ < this.cave[0][0].length)) { - if ($_$w(1, 27, $_$c), !cave[newX][newY][newZ].blocked) { - $_$w(1, 28, $_$c), validDirections.push([ - newX, - newY, - newZ - ]); - } - } - } - return $_$w(1, 29, $_$c), validDirections; -}; -$_$w(1, 30, $_$c), Submersible.prototype.investigate = function investigate() { - var $_$c = $_$wf(1); - return $_$w(1, 31, $_$c), this.cave[this.x][this.y][this.z].treasure; -}; -$_$w(1, 32, $_$c), Submersible.prototype.move = function move(nextX, nextY, nextZ) { - var $_$c = $_$wf(1); - if ($_$w(1, 33, $_$c), Math.abs(nextX - this.x + nextY - this.y + nextZ - this.z) !== 1) { - $_$w(1, 34, $_$c), $_$tracer.log('invalid movement', '', 1, 34); - return $_$w(1, 35, $_$c), false; - } - $_$w(1, 36, $_$c), this.x = nextX; - $_$w(1, 37, $_$c), this.y = nextY; - $_$w(1, 38, $_$c), this.z = nextZ; - return $_$w(1, 39, $_$c), true; -}; -const sub = ($_$w(1, 40, $_$c), new Submersible(cave, 0, 0, 0)); -function start() { - var $_$c = $_$wf(1); - if ($_$w(1, 41, $_$c), sub.currentPath.length === 0) { - $_$w(1, 42, $_$c), sub.currentPath.push([ - this.startingX, - this.startingY, - this.startingZ - ]); - } - if ($_$w(1, 43, $_$c), sub.scan().length === 0) { - $_$w(1, 44, $_$c), sub.currentPath[sub.x][sub.y][sub.z].blocked = true; - return $_$w(1, 45, $_$c), null; - } - $_$w(1, 46, $_$c), sub.scan().forEach(newCoords => { - var $_$c = $_$wf(1); - if ($_$w(1, 47, $_$c), sub.currentPath.filter(coords => { - var $_$c = $_$wf(1); - return $_$w(1, 48, $_$c), ($_$w(1, 49, $_$c), ($_$w(1, 51, $_$c), coords[0] === newCoords[0]) && ($_$w(1, 52, $_$c), coords[1] === newCoords[1])) && ($_$w(1, 50, $_$c), coords[2] === newCoords[2]); - }).length > 0) { - } else { - $_$w(1, 53, $_$c), sub.currentPath.push(newCoords); - $_$w(1, 54, $_$c), sub.move(...newCoords); - if ($_$w(1, 55, $_$c), ($_$w(1, 56, $_$c), sub.investigate()) && ($_$w(1, 57, $_$c), sub.treasuresFound.filter(coords => { - var $_$c = $_$wf(1); - return $_$w(1, 58, $_$c), ($_$w(1, 59, $_$c), ($_$w(1, 61, $_$c), coords[0] === sub.x) && ($_$w(1, 62, $_$c), coords[1] === sub.y)) && ($_$w(1, 60, $_$c), coords[2] === sub.z); - }).length === 0)) { - $_$w(1, 63, $_$c), sub.treasuresFound.push([ - sub.x, - sub.y, - sub.z - ]); - } - $_$w(1, 64, $_$c), start(); - } - }); - $_$w(1, 65, $_$c), sub.move(...sub.currentPath.pop()); - return $_$w(1, 66, $_$c), sub.treasuresFound; -} -const treasuresFound = ($_$w(1, 67, $_$c), start()); -$_$w(1, 68, $_$c), $_$tracer.log(treasuresFound, 'treasuresFound', 1, 68); -$_$wpe(1); \ No newline at end of file diff --git a/day01/prompt.txt b/day01/prompt.txt new file mode 100644 index 0000000..6136f06 --- /dev/null +++ b/day01/prompt.txt @@ -0,0 +1,39 @@ +--- Day 1: The Tyranny of the Rocket Equation --- +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. + +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 one star. Good luck! + +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. + +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. +The Fuel Counter-Upper needs to know the total fuel requirement. To find it, individually calculate 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? + +Your puzzle answer was 3198599. + +--- Part Two --- +During the second Go / No Go poll, the Elf in charge of the Rocket Equation Double-Checker stops the 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. + +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 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.) + +Your puzzle answer was 4795042. + +Both parts of this puzzle are complete! They provide two gold stars: ** + diff --git a/day02/prompt.txt b/day02/prompt.txt new file mode 100644 index 0000000..e35b494 --- /dev/null +++ b/day02/prompt.txt @@ -0,0 +1,72 @@ +--- Day 2: 1202 Program Alarm --- +On the way to your gravity assist around the Moon, your ship computer beeps angrily about a "1202 program alarm". On the radio, an Elf is already explaining how to handle the situation: "Don't 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!" + +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. + +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. + +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: + +1,9,10,3,2,3,11,0,99,30,40,50 +For the purposes of illustration, here is the same program split into multiple lines: + +1,9,10,3, +2,3,11,0, +99, +30,40,50 +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: + +1,9,10,70, +2,3,11,0, +99, +30,40,50 +Step forward 4 positions to reach the next opcode, 2. This opcode works just like the previous, but 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, +2,3,11,0, +99, +30,40,50 +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. +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? + +Your puzzle answer was 2692315. + +--- 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." + +"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"). + +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.) + +"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." + +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. + +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. + +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.) + +Your puzzle answer was 9507. + +Both parts of this puzzle are complete! They provide two gold stars: ** + + diff --git a/day03/prompt.txt b/day03/prompt.txt new file mode 100644 index 0000000..79182cf --- /dev/null +++ b/day03/prompt.txt @@ -0,0 +1,75 @@ +--- Day 3: Crossed Wires --- +The gravity assist was successful, and you're well on your way to the Venus refuelling station. 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). + +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. + +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: + +........... +........... +........... +....+----+. +....|....|. +....|....|. +....|....|. +.........|. +.o-------+. +........... +Then, if the second wire's path is U7,R6,D4,L4, it goes up 7, right 6, down 4, and left 4: + +........... +.+-----+... +.|.....|... +.|..+--X-+. +.|..|..|.|. +.|.-X--+.|. +.|..|....|. +.|.......|. +.o-------+. +........... +These wires cross at two locations (marked X), but the lower-left one is closer to the central port: its distance is 3 + 3 = 6. + +Here are a few more examples: + +R75,D30,R83,U83,L12,D49,R71,U7,L72 +U62,R66,U55,R34,D71,R55,D58,R83 = distance 159 +R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51 +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? + +Your puzzle answer was 2180. + +--- Part Two --- +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. + +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: + +........... +.+-----+... +.|.....|... +.|..+--X-+. +.|..|..|.|. +.|.-X--+.|. +.|..|....|. +.|.......|. +.o-------+. +........... +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. + +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: + +R75,D30,R83,U83,L12,D49,R71,U7,L72 +U62,R66,U55,R34,D71,R55,D58,R83 = 610 steps +R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51 +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? + +Your puzzle answer was 112316. + +Both parts of this puzzle are complete! They provide two gold stars: ** diff --git a/day04/prompt.txt b/day04/prompt.txt new file mode 100644 index 0000000..062d6da --- /dev/null +++ b/day04/prompt.txt @@ -0,0 +1,35 @@ +--- Day 4: Secure Container --- +You arrive at the Venus fuel depot only to discover it's protected by a password. The Elves had written the password on a sticky note, but someone threw it out. + +However, they do remember a few key facts about the password: + +It is a six-digit number. +The value is within the range given in your puzzle input. +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). +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). +123789 does not meet these criteria (no double). +How many different passwords within the range given in your puzzle input meet these criteria? + +Your puzzle answer was 1855. + +--- 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. + +Given this additional criterion, but still ignoring the range rule, the following are now true: + +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). +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? + +Your puzzle answer was 1253. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +Your puzzle input was 138307-654504. diff --git a/day05/prompt.txt b/day05/prompt.txt new file mode 100644 index 0000000..8b64ec7 --- /dev/null +++ b/day05/prompt.txt @@ -0,0 +1,86 @@ +--- Day 5: Sunny with a Chance of Asteroids --- +You're starting to sweat as the ship makes its way toward Mercury. The Elves suggest that you get 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: + +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 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: + +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. + +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 digits of the first value in an instruction. Parameter modes are single digits, one per parameter, read right-to-left from the opcode: the first parameter's mode is in the hundreds digit, the second parameter's mode is in the thousands digit, the third parameter's mode is in the ten-thousands 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): + +ABCDE + 1002 + +DE - two-digit opcode, 02 == opcode 2 + C - mode of 1st parameter, 0 == position mode + B - mode of 2nd parameter, 1 == immediate mode + A - mode of 3rd parameter, 0 == position mode, + omitted due to being a leading zero +This instruction multiplies its first two parameters. The first parameter, 4 in position mode, works like it did before - its value is the value stored at address 4 (33). The second parameter, 3 in immediate mode, simply has value 3. The result of this operation, 33 * 3 = 99, is written 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. + +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. +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. + +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. + +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? + +Your puzzle answer was 11049715. + +--- Part Two --- +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. + +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 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 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 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. + +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. + +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,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,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,3,1105,-1,9,1101,0,0,12,4,12,99,1 (using immediate mode) +Here's a larger example: + +3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31, +1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104, +999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99 +The above example program uses an input instruction to ask for a single number. The program will then output 999 if the input value is below 8, output 1000 if the input value is equal to 8, or 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. + +What is the diagnostic code for system ID 5? + +Your puzzle answer was 2140710. diff --git a/day06/prompt.txt b/day06/prompt.txt new file mode 100644 index 0000000..26c1f9d --- /dev/null +++ b/day06/prompt.txt @@ -0,0 +1,104 @@ +--- Day 6: Universal Orbit Map --- +You've landed at the Universal Orbit Map facility on Mercury. Because navigation in space often involves transferring between orbits, the orbit maps here are useful for finding efficient routes between, for example, you and Santa. You download a map of the local orbits (your puzzle input). + +Except for the universal Center of Mass (COM), every object in space is in orbit around exactly one other object. An orbit looks roughly like this: + + \ + \ + | + | +AAA--> o o <--BBB + | + | + / + / +In this diagram, the object BBB is in orbit around AAA. The path that BBB takes around AAA (drawn with lines) is only partly shown. In the map data, this orbital relationship is written AAA)BBB, 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. + +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 +B)C +C)D +D)E +E)F +B)G +G)H +D)I +E)J +J)K +K)L +Visually, the above map of orbits looks like this: + + G - H J - K - L + / / +COM - B - C - D - E - F + \ + I +In this visual representation, when two objects are connected by a line, the one on the right directly orbits the one on the left. + +Here, we can count the total number of orbits as follows: + +D directly orbits C and indirectly orbits B and COM, a total of 3 orbits. +L directly orbits K and indirectly orbits J, E, D, C, B, and COM, a total of 7 orbits. +COM orbits nothing. +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? + +Your puzzle answer was 301100. + +--- Part Two --- +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. + +For example, suppose you have the following map: + +COM)B +B)C +C)D +D)E +E)F +B)G +G)H +D)I +E)J +J)K +K)L +K)YOU +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 +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: + +K to J +J to E +E to D +D to I +Afterward, the map of orbits looks like this: + + G - H J - K - L + / / +COM - B - C - D - E - F + \ + I - SAN + \ + 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.) + +Your puzzle answer was 547. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +A diff --git a/day07/prompt.txt b/day07/prompt.txt new file mode 100644 index 0000000..4eb6156 --- /dev/null +++ b/day07/prompt.txt @@ -0,0 +1,79 @@ +--- Day 7: Amplification Circuit --- +Based on the navigational maps, you're going to need to send more power to your ship's thrusters to reach Santa in time. To do this, you'll need to configure a series of amplifiers already installed on the ship. + +There are five amplifiers connected in series; each one receives an input signal and produces an output signal. They are connected such that the first amplifier's output leads to the second amplifier's input, the second amplifier's output leads to the third amplifier's input, and so on. The first amplifier's input value is 0, and the last amplifier's output leads to your ship's thrusters. + + O-------O O-------O O-------O O-------O O-------O +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. + +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. + +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. + +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 could determine the output signal that gets sent from amplifier E to the thrusters with the following steps: + +Start the copy of the amplifier controller software that will run on amplifier A. At its first input instruction, provide it the amplifier's phase setting, 3. At its second input instruction, provide it the input signal, 0. After some calculations, it will use an output instruction to indicate the amplifier's output signal. +Start the software for amplifier B. Provide it the phase setting (1) and then whatever output signal was produced from amplifier A. It will then produce a new output signal destined for amplifier C. +Start the software for amplifier C, provide the phase setting (2) and the value from amplifier B, then collect its output signal. +Run amplifier D's software, provide the phase setting (4) and input value, and collect its output signal. +Run amplifier E's software, provide the phase setting (0) and input value, and collect its output signal. +The final output signal from amplifier E would be sent to the thrusters. However, this phase setting sequence may not have been the best one; another sequence might have sent a higher signal to the thrusters. + +Here are some example programs: + +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): + +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): + +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? + +Your puzzle answer was 21760. + +--- Part Two --- +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: + + O-------O O-------O O-------O O-------O O-------O +0 -+->| Amp A |->| Amp B |->| Amp C |->| Amp D |->| Amp E |-. + | O-------O O-------O O-------O O-------O O-------O | + | | + '--------------------------------------------------------+ + | + v + (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. + +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. + +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. + +Here are some example programs: + +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): + +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? + +Your puzzle answer was 69816958. + +Both parts of this puzzle are complete! They provide two gold stars: ** diff --git a/day08/prompt.txt b/day08/prompt.txt new file mode 100644 index 0000000..1b81d2e --- /dev/null +++ b/day08/prompt.txt @@ -0,0 +1,57 @@ +--- Day 8: Space Image Format --- +The Elves' spirits are lifted when they realize you have an opportunity to reboot one of their Mars rovers, and so they are curious if you would spend a brief sojourn on Mars. You land your ship near the rover. + +When you reach the rover, you discover that it's already in the process of rebooting! It's just waiting for someone to enter a BIOS password. The Elf responsible for the rover takes a picture of the password (your puzzle input) and sends it to you via the Digital Sending Network. + +Unfortunately, images sent via the Digital Sending Network aren't encoded with any normal encoding; instead, they're encoded in a special Space Image Format. None of the Elves seem to remember why this is the case. They send you the instructions to decode it. + +Images are sent as a series of digits that each represent the color of a single pixel. The digits 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 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. + +For example, given an image 3 pixels wide and 2 pixels tall, the image data 123456789012 corresponds to the following image layers: + +Layer 1: 123 + 456 + +Layer 2: 789 + 012 +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? + +Your puzzle answer was 1806. + +--- Part Two --- +Now you're ready to decode the image. The image is rendered by stacking the layers and aligning the pixels with the same positions in each layer. The digits indicate the color of the corresponding 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. + +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 + 22 + +Layer 2: 11 + 22 + +Layer 3: 22 + 12 + +Layer 4: 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-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-right pixel is black because the only visible pixel in that position is 0 (from layer 4). +So, the final image looks like this: + +01 +10 +What message is produced after decoding your image? + +Your puzzle answer was JAFRA. + +Both parts of this puzzle are complete! They provide two gold stars: ** diff --git a/day10/prompt.txt b/day10/prompt.txt new file mode 100644 index 0000000..10b364f --- /dev/null +++ b/day10/prompt.txt @@ -0,0 +1,161 @@ +--- Day 10: Monitoring Station --- +You fly into the asteroid belt and reach the Ceres monitoring station. The Elves here have an emergency: they're having trouble tracking all of the asteroids and can't be sure they're safe. + +The Elves would like to build a new monitoring station in a nearby area of space; they hand you a map of all of the asteroids in that region (your puzzle input). + +The map indicates whether each position is empty (.) or contains an asteroid (#). The asteroids are much smaller than they appear on the map, and every asteroid is exactly in the center of its marked position. The asteroids can be described with X,Y coordinates where X is the distance from the left 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. + +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 is the one at 1,0; its view of this asteroid is blocked by the asteroid at 2,2.) All other asteroids are worse locations; they can detect 7 or fewer other asteroids. Here is the number of other asteroids a monitoring station on each asteroid could detect: + +.7..7 +..... +67775 +....7 +...87 +Here is an asteroid (#) and some examples of the ways its line of sight might be blocked. If there were another asteroid at the location of a capital letter, the locations marked with the corresponding lowercase letter would be blocked and could not be detected: + +#......... +...A...... +...B..a... +.EDCG....a +..F.c.b... +.....c.... +..efd.c.gb +.......c.. +....f...c. +...e..d..c +Here are some larger examples: + +Best is 5,8 with 33 other asteroids detected: + +......#.#. +#..#.#.... +..#######. +.#.#.###.. +.#..#..... +..#....#.# +#..#....#. +.##.#..### +##...#..#. +.#....#### +Best is 1,2 with 35 other asteroids detected: + +#.#...#.#. +.###....#. +.#....#... +##.#.#.#.# +....#.#.#. +.##..###.# +..#...##.. +..##....## +......#... +.####.###. +Best is 6,3 with 41 other asteroids detected: + +.#..#..### +####.###.# +....###.#. +..###.##.# +##.##.#.#. +....###..# +..#.#..#.# +#..#.#.### +.##...##.# +.....#.#.. +Best is 11,13 with 210 other asteroids detected: + +.#..##.###...####### +##.############..##. +.#.######.########.# +.###.#######.####.#. +#####.##.#.##.###.## +..#####..#.######### +#################### +#.####....###.#.#.## +##.################# +#####.##.###..####.. +..######..##.####### +####.##.####...##..# +.#####..#.######.### +##...#.##########... +#.##########.####### +.####.#.###.###.#.## +....##.##.###..##### +.#.#.###########.### +#.#.#.#####.####.### +###.##.####.##.#..## +Find the best location for a new monitoring station. How many other asteroids can be detected from that location? + +Your puzzle answer was 227. + +--- Part Two --- +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. + +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. + +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: + +.#....#####...#.. +##...##.#####..## +##...#...#.#####. +..#.....X...###.. +..#.#.....#....## +The first nine asteroids to get vaporized, in order, would be: + +.#....###24...#.. +##...##.13#67..9# +##...#...5.8####. +..#.....X...###.. +..#.#.....#....## +Note that some asteroids (the ones behind the asteroids marked 1, 5, and 7) won't have a chance to be vaporized until the next full rotation. The laser continues rotating; the next nine to be vaporized are: + +.#....###.....#.. +##...##...#.....# +##...#......1234. +..#.....X...5##.. +..#.9.....8....76 +The next nine to be vaporized are then: + +.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 +................. +........X....89.. +................. +In the large example above (the one with the best monitoring station location at 11,13): + +The 1st asteroid to be vaporized is at 11,12. +The 2nd asteroid to be vaporized is at 12,1. +The 3rd asteroid to be vaporized is at 12,2. +The 10th asteroid to be vaporized is at 12,8. +The 20th asteroid to be vaporized is at 16,0. +The 50th asteroid to be vaporized is at 16,9. +The 100th asteroid to be vaporized is at 10,16. +The 199th asteroid to be vaporized is at 9,6. +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.) + +Your puzzle answer was 604. + +Both parts of this puzzle are complete! They provide two gold stars: ** diff --git a/day12/prompt.txt b/day12/prompt.txt new file mode 100644 index 0000000..1759e22 --- /dev/null +++ b/day12/prompt.txt @@ -0,0 +1,223 @@ +--- Day 12: The N-Body Problem --- +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. + +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. + +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. + +For example, suppose your scan reveals the following positions: + + + + + +Simulating the motion of these moons would produce the following: + +After 0 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 1 step: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 2 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 3 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 4 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 5 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 6 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 7 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 8 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 9 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 10 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= +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 +In the above example, adding together the total energy for all moons after 10 steps produces the total energy in the system, 179. + +Here's a second example: + + + + + +Every ten steps of simulation for 100 steps produces: + +After 0 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 10 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 20 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 30 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 40 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 50 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 60 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 70 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 80 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 90 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 100 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +Energy after 100 steps: +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 +What is the total energy in the system after simulating the moons given in your scan for 1000 steps? + +Your puzzle answer was 9139. + +--- Part Two --- +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. + +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: + +After 0 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 2770 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 2771 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= + +After 2772 steps: +pos=, vel= +pos=, vel= +pos=, vel= +pos=, vel= +Of course, the universe might last for a very long time before repeating. Here's a copy of the second example from above: + + + + + +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. + +How many steps does it take to reach the first state that exactly matches a previous state? + +Your puzzle answer was 420788524631496. + +Both parts of this puzzle are complete! They provide two gold stars: ** diff --git a/day14/input.txt b/day14/input.txt new file mode 100644 index 0000000..2127948 --- /dev/null +++ b/day14/input.txt @@ -0,0 +1,55 @@ +13 RXWQR => 4 JXCXB +7 FDGDX => 7 XRWJ +3 JBVN, 25 JFRXJ => 3 TPDSB +13 HZDWS, 11 RZNJR => 3 SVFT +5 FDGDX, 4 RZNJR, 41 ZGXGP => 8 LBVM +1 LJDRB => 9 RXWQR +2 RDPWQ => 8 JBVN +2 CZCB => 8 CXHK +4 JXCXB, 1 FPQRV => 5 TCBSQ +6 FDGDX => 8 TWGNB +1 RJBTL => 5 VRVDQ +2 XRWJ, 3 HZDWS, 12 LBVM => 6 KSJD +15 HPXST, 1 KMKR, 7 SLTX, 1 PRWD, 14 RCLB, 31 TPDSB, 3 GWXJP, 3 TPQZ => 8 XRLZR +1 RBLT, 2 RTFKN, 1 CZCB => 8 DNRP +131 ORE => 8 TFGJ +2 JFRXJ, 1 VRVDQ, 26 TWGNB => 5 CFPZ +2 SMPW, 1 TWGNB => 8 RZNJR +20 HRZP => 6 RDPWQ +1 RCLB, 4 GJNK, 4 QGJL => 4 HZDWS +7 CXHK, 2 XTMRV, 6 WSNPZ, 12 LQXCP, 19 PMWJ, 17 GJNK, 26 XRLZR, 36 LWFQ => 1 FUEL +131 ORE => 8 KMKR +1 LJDRB, 12 TFGJ, 10 RXWQR => 7 RPKZ +10 RVXT, 1 RDPWQ => 8 JFRXJ +1 QXBTX => 9 TPQZ +1 ZGXGP => 5 FZGF +1 RTFKN, 1 DNRP => 2 FDGDX +19 CZCB, 1 RBLT => 4 SMPW +2 DNRP, 1 SMPW => 9 RWSH +1 ZGXGP, 5 TCBSQ, 22 SMPW => 5 GWXJP +1 HBSKF => 3 LQXCP +1 ZGXGP, 2 KSJD, 9 CFPZ => 7 CLGXQ +186 ORE => 8 LJDRB +1 TPQZ, 2 HBSKF => 1 QGJL +8 FZGF, 6 FDGDX => 3 PMWJ +9 KMKR => 1 CZCB +21 TFGJ, 3 RVXT => 5 HRZP +39 FDGDX, 24 TPDSB => 2 RCLB +4 HRZP => 2 GJNK +6 RZNJR => 2 HBSKF +101 ORE => 8 RVXT +1 RCLB => 8 QXBTX +1 RJBTL => 7 RBLT +2 CFPZ, 2 JXCXB, 4 TPQZ => 1 LWFQ +1 QGJL, 24 GJNK, 6 TWGNB, 1 SLTX, 18 JFRXJ, 6 MSNM, 6 FDGDX, 2 JXCXB => 5 WSNPZ +4 RZNJR => 6 FPQRV +12 LJDRB, 10 JFRXJ, 1 ZGXGP => 5 TXZVH +13 KSJD, 11 FXGW => 9 PRWD +11 SVFT, 2 HZDWS, 1 CLGXQ, 1 LQXCP, 6 JXCXB, 11 PRWD => 5 XTMRV +27 TWGNB, 7 FPQRV => 2 SLTX +2 HRZP, 6 RXWQR => 9 RJBTL +2 CXHK, 1 RPKZ => 1 RTFKN +7 RWSH, 12 JBVN, 6 FXGW => 2 ZGXGP +1 TXZVH, 4 FPQRV => 8 MSNM +16 TPDSB, 1 FXGW => 5 HPXST +1 VRVDQ => 2 FXGW diff --git a/day14/prompt.txt b/day14/prompt.txt new file mode 100644 index 0000000..c5df92b --- /dev/null +++ b/day14/prompt.txt @@ -0,0 +1,84 @@ +--- Day 14: Space Stoichiometry --- +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. + +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. + +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. + +Suppose your nanofactory produces the following list of reactions: + +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 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? diff --git a/day16/input.txt b/day16/input.txt new file mode 100644 index 0000000..50a516a --- /dev/null +++ b/day16/input.txt @@ -0,0 +1 @@ +59766977873078199970107568349014384917072096886862753001181795467415574411535593439580118271423936468093569795214812464528265609129756216554981001419093454383882560114421882354033176205096303121974045739484366182044891267778931831792562035297585485658843180220796069147506364472390622739583789825303426921751073753670825259141712329027078263584903642919122991531729298497467435911779410970734568708255590755424253797639255236759229935298472380039602200033415155467240682533288468148414065641667678718893872482168857631352275667414965503393341925955626006552556064728352731985387163635634298416016700583512112158756656289482437803808487304460165855189 diff --git a/day16/prompt.txt b/day16/prompt.txt new file mode 100644 index 0000000..ae7b619 --- /dev/null +++ b/day16/prompt.txt @@ -0,0 +1,68 @@ +--- Day 16: Flawed Frequency Transmission --- +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. + +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 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 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 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. + +When applying the pattern, skip the very first value exactly once. (In other words, offset the whole pattern left by one.) So, for the second element of the output list, the actual pattern used would be: 0, 1, 1, 0, 0, -1, -1, 0, 0, 1, 1, 0, 0, -1, -1, .... + +After using this process to calculate each element of the output list, the phase is complete, and the output list of this phase is used as the new input list for the next phase, if any. + +Given the input signal 12345678, below are four phases of FFT. Within each phase, each output digit is calculated on a single line with the result at the far right; each multiplication operation shows the input digit on the left and the pattern value on the right: + +Input signal: 12345678 + +1*1 + 2*0 + 3*-1 + 4*0 + 5*1 + 6*0 + 7*-1 + 8*0 = 4 +1*0 + 2*1 + 3*1 + 4*0 + 5*0 + 6*-1 + 7*-1 + 8*0 = 8 +1*0 + 2*0 + 3*1 + 4*1 + 5*1 + 6*0 + 7*0 + 8*0 = 2 +1*0 + 2*0 + 3*0 + 4*1 + 5*1 + 6*1 + 7*1 + 8*0 = 2 +1*0 + 2*0 + 3*0 + 4*0 + 5*1 + 6*1 + 7*1 + 8*1 = 6 +1*0 + 2*0 + 3*0 + 4*0 + 5*0 + 6*1 + 7*1 + 8*1 = 1 +1*0 + 2*0 + 3*0 + 4*0 + 5*0 + 6*0 + 7*1 + 8*1 = 5 +1*0 + 2*0 + 3*0 + 4*0 + 5*0 + 6*0 + 7*0 + 8*1 = 8 + +After 1 phase: 48226158 + +4*1 + 8*0 + 2*-1 + 2*0 + 6*1 + 1*0 + 5*-1 + 8*0 = 3 +4*0 + 8*1 + 2*1 + 2*0 + 6*0 + 1*-1 + 5*-1 + 8*0 = 4 +4*0 + 8*0 + 2*1 + 2*1 + 6*1 + 1*0 + 5*0 + 8*0 = 0 +4*0 + 8*0 + 2*0 + 2*1 + 6*1 + 1*1 + 5*1 + 8*0 = 4 +4*0 + 8*0 + 2*0 + 2*0 + 6*1 + 1*1 + 5*1 + 8*1 = 0 +4*0 + 8*0 + 2*0 + 2*0 + 6*0 + 1*1 + 5*1 + 8*1 = 4 +4*0 + 8*0 + 2*0 + 2*0 + 6*0 + 1*0 + 5*1 + 8*1 = 3 +4*0 + 8*0 + 2*0 + 2*0 + 6*0 + 1*0 + 5*0 + 8*1 = 8 + +After 2 phases: 34040438 + +3*1 + 4*0 + 0*-1 + 4*0 + 0*1 + 4*0 + 3*-1 + 8*0 = 0 +3*0 + 4*1 + 0*1 + 4*0 + 0*0 + 4*-1 + 3*-1 + 8*0 = 3 +3*0 + 4*0 + 0*1 + 4*1 + 0*1 + 4*0 + 3*0 + 8*0 = 4 +3*0 + 4*0 + 0*0 + 4*1 + 0*1 + 4*1 + 3*1 + 8*0 = 1 +3*0 + 4*0 + 0*0 + 4*0 + 0*1 + 4*1 + 3*1 + 8*1 = 5 +3*0 + 4*0 + 0*0 + 4*0 + 0*0 + 4*1 + 3*1 + 8*1 = 5 +3*0 + 4*0 + 0*0 + 4*0 + 0*0 + 4*0 + 3*1 + 8*1 = 1 +3*0 + 4*0 + 0*0 + 4*0 + 0*0 + 4*0 + 3*0 + 8*1 = 8 + +After 3 phases: 03415518 + +0*1 + 3*0 + 4*-1 + 1*0 + 5*1 + 5*0 + 1*-1 + 8*0 = 0 +0*0 + 3*1 + 4*1 + 1*0 + 5*0 + 5*-1 + 1*-1 + 8*0 = 1 +0*0 + 3*0 + 4*1 + 1*1 + 5*1 + 5*0 + 1*0 + 8*0 = 0 +0*0 + 3*0 + 4*0 + 1*1 + 5*1 + 5*1 + 1*1 + 8*0 = 2 +0*0 + 3*0 + 4*0 + 1*0 + 5*1 + 5*1 + 1*1 + 8*1 = 9 +0*0 + 3*0 + 4*0 + 1*0 + 5*0 + 5*1 + 1*1 + 8*1 = 4 +0*0 + 3*0 + 4*0 + 1*0 + 5*0 + 5*0 + 1*1 + 8*1 = 9 +0*0 + 3*0 + 4*0 + 1*0 + 5*0 + 5*0 + 1*0 + 8*1 = 8 + +After 4 phases: 01029498 +Here are the first eight digits of the final output list after 100 phases for some larger inputs: + +80871224585914546619083218645595 becomes 24176176. +19617804207202209144916044189917 becomes 73745418. +69317163492948606335995924319873 becomes 52432133. +After 100 phases of FFT, what are the first eight digits in the final output list? diff --git a/day18/input.txt b/day18/input.txt new file mode 100644 index 0000000..b3b7bb9 --- /dev/null +++ b/day18/input.txt @@ -0,0 +1,81 @@ +################################################################################# +#...........#.....#.#...........#.....#.#...#...#...........#...........#......u# +###.#######.#.###.#.#.###.#######.###.#.#.#.###.#.#######.###.#####.###.###.###.# +#...#.....#.#.#.#.#.....#.#.......#...#.#.#...#.#.#.....#.........#...#...#...#.# +#.#####I#.#.#.#.#.#######.#.#######.###.#.###.#.#.#####.#############.###.#####.# +#.....#.#.#.#.#...........#.....#.#.....#...#.#.#.......#.....#.....#...#...#...# +#.###.#.#.#.#.#################.#.#####.#.#.#.#J#######.#.#.#.#.###.###.###.#.#.# +#...#.#.#.....#.....#...........#.#.....#.#.#.#...#.....#.#.#.#.#.....#.#...Y.#.# +#####.#########.###.#.###########.#.#######.#.#.#.#.#####.#H#.#.#####.#.#######.# +#...#...#.......#...#...#...#.....#.....#...#...#.#...#.#.#.#.#...#...#.....#...# +#.#.###.#.#######.#####.#.#.#.###.#####.#.#######.###.#.#.#.#####.###.###.#.##### +#.#.....#.#..k#..z......#.#.#...#.....#.#.....#.....#.#...#.#...#...#...#.#.....# +#.#####.#.#.#.###########.#####.#.#####.#.###.#######.#.###.#.#.###.###.#######.# +#.....#l#.R.#.....#.......#.....#...#...#...#.....#...#.#...#.#.....#...........# +#.###.#.#######.#.###.#.###.#######.#.#####.#####.#.#####.###.###.#############.# +#.#.#.#...#...#.#...#.#...#.#.....#.#...#.#.#.#...#...#...#...#...#...#.....#...# +#.#.#.###.#.#.#####.#.###.#.#.#.###.###.#.#.#.#.#####.#.###.#.#####.#.#.###.#.### +#...#.#...#.#.......#...#...#.#d..#.#...#..q..#...#...#...#.#.#.....#...Z.#r#.#.# +###.#.###.#V###########.#####.###.#.#.###########O#.#####.#.###.###########.#.#.# +#...#...#.#........f..#.#.....#...#.#.#.#.......#.#.#.....#.........#.......#...# +#######.#############.#.#######.###.#.#.#.#####.#.#.#.###.#########.#.#########.# +#.......#...........#.#.......#...#...#.#...#.#.#.#...#.#...#...#...#...#.#..e..# +#.#######.###.#.#############.###.#####.###.#.#.#.#####.###.###.###.###.#.#.##### +#p........#.#.#.#.......#...#...#.....#.#...#.#.#.#.......#...#.F.#...#.#...#.K.# +#.#########.#.###.#.###.#.#.###.###.#.#.#.###.#.#.#N#####.###.###.#####.#####.#.# +#...#.......#.....#...#.#.#.....#...#...#.#.......#.#...#...#...#.....#.......#.# +###.#.###.###########.###.#######.#####.#.#########.#.#####.###.#####.#####.###.# +#.#.#...#...........#.#...#.....#...S.#.#.#...#.......#...#...#.....#.....#...#.# +#.#.###########.###.#.#.###.###.#####.#.#.#.#.#.#######.#.###.#####.#####.###.#.# +#...#.........#.#...#...#...#.#.......#.#...#...#...#...#...#..x..#.#...#...#.#.# +#.###.#######.#.#########.#.#.#########.#.#######.#.#.#####.###.###.#.#####.###.# +#.....#.....#.#.......#...#.#.#.......#.#.#.......#.#.#.......#.#...#.#...#...#.# +#########.###.#.###.###.###.#.#.#####.#.#.#######.#.#.#######.#.#.###.#.#.###.#.# +#.....#...#...#.#.#.#...#...#...#..t#...#...#.....#.#.....#.....#...#...#...#..v# +#.###.#.###.###.#.#.#.###.###.#####.#######.#.#####.#####.###.#####.#####.####### +#.#.....#...#.....#.....#.#...........#.#...#.#...#.#...#...#.#...#.....#.......# +#.#######.#######.#####.#.###########.#.#.###.#.###.#.#.###.###.#.#####.#####.#.# +#.......#.#.....#.#...#.#.......#.#...#.#.....#...#...#...#.....#.....#.#...#.#.# +#.#####.#.#X###.###.#.#########.#.#.###.#######.#.#######.###########.#.#.#P###.# +#.....#.....#.......#...........#...............#.........T....g....#.....#.....# +#######################################.@.####################################### +#..y#...#.................#...#...................#.....#.........#.....#...#...# +#.###.#.#.#########.#.#####E#.#####.#.#.#.###.#####.###.###.#.###.###.#.#.#.#.#.# +#.#...#...#...#.#.U.#.#.....#.#...#.#.#.#.#.#...#...#.#...#.#...#.#...#.#.#.#.#.# +#.#.#######.#.#.#.#####.#####.#.#.###.#.#.#.###.#.###.###.#####.#.#.###.#A#.#.#.# +#.#...#...C.#...#.........#..a#.#...#.#.#.....#...#.#...#.#.....#.#.#...#.#b..#.# +#.###.#.#######.###########.###.###.#.#.#####.#####.#.#.#.#.#####.#.#.###.#####.# +#.....#.#.......#.#...B...#.#...#.#...#.#.#...#...#...#.#.#.#...#...#...#.#.....# +#.#####.#.#######.#.#####.#.#.#.#.#####.#.#.###.#.#####.#.#.#.#.#######.#.#.##### +#.W.....#.#...#...#...#...#.#.#.#.....#.#.#.....#.......#.#...#.#.....#...#...#.# +#########.#.#.###.###.#.###.#.#.#.#.###.#.#############.#.###.#.###.#.#.#####.#.# +#.......#...#...#.#...#.#...#.#.#.#.....#.....#.......#.#...#.#...#.#.#.#...#...# +#####.#.#######.#.#.###.###.#.#.#.#######.#####.#.#####.###.#.###.###.#.#.#.###.# +#.....#.......#.#.#.#...#...#.#.#.....#.#.....#.#.........#.#.#.#...#...#.#c#...# +#.#########.###.#.#.###.#.#####.#####.#.#.###.#.###########.#.#.###.#.###.#.##### +#.#.....#...#...#.#...#...#.G.#.#...#.#.#...#...#...#...#...#...#.#.#...#.#.....# +#.#.#####.###.###.###.#####.#.#.#.#.#.#.###.#####.###.#.#.#####.#.#.#####.#####.# +#.#.....#...#.#.....#.#.....#...#.#.#.#.#.#...#.....#.#...#...#...#..w......#.#.# +#.#.###.###.#.###.###.###.#########.#.#.#.###.#.###.#.###.#.#.###.#########.#.#.# +#.#...#...#.#...#.#...#...#.........#.#.#...#.#.#.#.#.#...#.#...#.#...#...#...#.# +#.#######.#.###.#.#.###.#######.#####.#.#.#.#.#.#.#.#.#####.###.###.#.#.#.#####.# +#.......#.#.#...#.#...#.#.......#.....#.#.#.#.#...#.#...#...#.#.....#...#...#...# +#.#####.#.#.#.###.#####.###.#.###.#####.#.#.#.#####.###.#.###.#######.#####.#.#.# +#.#...#.#...#.#...#.....#...#.#...#.....#.#.#.....#...#...#...#.....#.....#.#.#.# +#.#.#.#.#####.#.#.#.#####.###.#.#####.#.#.#######.###.#####.###.###.#######.#.### +#.#.#...#.....#.#...#...#...#.#....s..#.#.....#...#.....#...#...#.........#.#...# +#.#.###.#.#####.#####.#.#.#.#.#########.#.###.#.###.###.#.###.#.#########.#.###.# +#.#..m#.#.....#...#...#...#.#.#.......#.#.#.#.#.#...#...#...#.#.#...#...#...#..i# +#.###.#######.#.#.#.#######.#.#####.#.#.#.#.#.#.#.###.#####.#.###.#.#.#######.#.# +#...#.........#.#.#.......#.#...#...#.#.#.#.#...#.#...#...#.#.....#.#.......#.#.# +###.#############.#######.#.###.#.#.###.#.#.#####.#.###.#.#.#.#####Q###.###M#.### +#...#.....#.......#..j#...#.#.....#.#...#...#.....#...#.#.#.#.#.....#...#...#...# +#.#####.#.###.#######.#.###.#########.#####.#.#.#####.#.#.#.###.#####.###.###.#.# +#...#...#.....#.....#...#.#.......#...#.#...#.#.#...#.#.#.#.....#.....#.#.#...#.# +###.#.#########.###.#.###.#######.#.###.#.#####.#.#.#.#.###########.###.#.#####.# +#.#.#.............#.#.#.....#....o#.#...#.......#.#.#.#...#.......#.#..h#...#...# +#.#.###############.#.#####.#.###.#.###.###########.#.#.#.#.###.#.#.#.#.###.#.### +#.#...#.........#...#.......#.#...#.D...#...#.......#.#.#...#...#...#.#...#.#...# +#.###.#.#######.#.#########.#.#########.#.#.#.###.###.#######.#######.#.###.###L# +#.......#.........#.........#..........n#.#.....#.............#.......#.........# +################################################################################# diff --git a/day18/prompt.txt b/day18/prompt.txt new file mode 100644 index 0000000..07ca347 --- /dev/null +++ b/day18/prompt.txt @@ -0,0 +1,93 @@ +--- Day 18: Many-Worlds Interpretation --- +As you approach Neptune, a planetary security system detects you and activates a giant tractor beam 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 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. + +For example, suppose you have the following map: + +######### +#b.A.@.a# +######### +Starting from the entrance (@), you can only access a large door (A) and a key (a). Moving toward the door doesn't help you, but you can move 2 steps to collect the key, unlocking A in the process: + +######### +#b.....@# +######### +Then, you can move 6 steps to collect the only other key, b: + +######### +#@......# +######### +So, collecting every key took a total of 8 steps. + +Here is a larger example: + +######################## +#f.D.E.e.C.b.A.@.a.B.c.# +######################.# +#d.....................# +######################## +The only reasonable move is to take key a and unlock door A: + +######################## +#f.D.E.e.C.b.....@.B.c.# +######################.# +#d.....................# +######################## +Then, do the same with key b: + +######################## +#f.D.E.e.C.@.........c.# +######################.# +#d.....................# +######################## +...and the same with key c: + +######################## +#f.D.E.e.............@.# +######################.# +#d.....................# +######################## +Now, you have a choice between keys d and e. While key e is closer, collecting it now would be slower in the long run than collecting key d first, so that's the best choice: + +######################## +#f...E.e...............# +######################.# +#@.....................# +######################## +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: + +######################## +#...............b.C.D.f# +#.###################### +#.....@.a.B.c.d.A.e.F.g# +######################## +Shortest path is 132 steps: b, a, c, d, f, e, g + +################# +#i.G..c...e..H.p# +########.######## +#j.A..b...f..D.o# +########@######## +#k.E..a...g..B.n# +########.######## +#l.F..d...h..C.m# +################# +Shortest paths are 136 steps; +one is: a, f, b, j, g, n, h, d, l, o, e, p, c, i, k, m + +######################## +#@..............ac.GI.b# +###d#e#f################ +###A#B#C################ +###g#h#i################ +######################## +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? + + diff --git a/day20/input.txt b/day20/input.txt new file mode 100644 index 0000000..0bc01c2 --- /dev/null +++ b/day20/input.txt @@ -0,0 +1,123 @@ + S U A R G V B L + X Y A U T M Y G + #######################################.#######.#.###.#####.#####.#######.#######.##################################### + #...#.#.#...................#...#.#...#...#.#.#.#.....#...#...#...#.#.......#.....#...#...#.....#.........#.....#...#.# + ###.#.#.###.###.#####.###.#####.#.#.#.#.###.#.#.#.#####.#.###.#.###.#######.#.###.#.#####.###.###.#####.#.#.#####.#.#.# + #.............#.#.....#.............#...#...#.#.#.#...#.#.#...#.....#...#.#.#...#.......#.........#...#.#.#...#.#.#.#.# + ###.#####.#.#.#.#.#.#####.#####.#.#######.#.###.#.#.#.#.#.#.###.#.#.###.#.#.###.#####.###.#########.#########.#.###.#.# + #...#.....#.#.#.#.#.#.....#...#.#.....#.#.#.....#...#.#.#.#...#.#.#...#.#...#.......#.#.........#.....#.....#...#.....# + #.#####.###.#.###############.###.#####.#.###########.#.#.#.###.###.###.#.#####.#.#.###.#####.###.#########.#.#.#####.# + #.#.#.....#.#.#.........................#.......#.#...#.#.....#.#.#...#.....#...#.#...#...#...........#.......#...#.#.# + ###.#.#.###########.###########.#######.###.#.#.#.#.###.#####.###.#.#####.###.#########.#######.###########.###.###.#.# + #.....#.#.#...#...#.#.#.#.#.#...#.#.....#...#.#.#...#...#...#.#.......#.....#.#.#.#.#.#.......#.#...#...#...#.#.#.#.#.# + #.###.###.#.#####.###.#.#.#.#.###.#.#.###.#####.#.#.###.#.#########.#.#.###.#.#.#.#.#.#.#.#######.#####.#.#.#.#.#.#.#.# + #.#.....#.#.............#.#.#.#.....#.#.#.#.....#.#.#.#...#.....#.#.#.#.#...#.#.#.......#.#.....#.#.#...#.#.#.#.#...#.# + #####.###.#############.#.#.#####.#.###.###.###.###.#.#.#.#####.#.#.#######.#.#.#.###.#.#.###.###.#.###.###.#.###.###.# + #.#.#.#.#.#.....#.......#.......#.#...#.....#.#.#...#.#.#...#.....#.#.#.#...#.......#.#.#.#.....#...#...#...#.....#...# + #.#.###.#.#.#.#.#####.#.###.###.###.#####.#.#.#.###.#.#.###.###.###.#.#.#.#.###.###########.#####.#.###.###.#.#.#####.# + #.....#...#.#.#...#.#.#...#...#.....#.....#.#.#.#...#.....#.#.........#...#.#.........#.....#...#.#...#.......#.#.....# + #####.#.#####.#.#.#.#.#.#######.###.###.#.###.###.#.#.#.#####.#####.#######.#.#########.#######.#.#####.#############.# + #.#.#...#...#.#.#.#.#.#.........#...#...#...#.....#.#.#.....#.#.#.....#...#.#.....#.........#.#.#.....#.....#.#.#.....# + #.#.###.#.#####.###.###.#####.###.#########.#.###.#######.#####.###.#####.#.#.#####.#.#######.#.#.#.###.#.#.#.#.###.#.# + #.#.#...#.....#...#.....#.#.....#...#.#...#.#.#...#.#.....#...#.......#.#...#...#...#.#.#.#.......#.#...#.#.#.#...#.#.# + #.#.###.#.#####.#####.#.#.#######.###.#.###.###.#.#.###.###.###.#.#.###.#.###.#####.###.#.#.#####.###.#######.#.#####.# + #.....#.#...#.#...#.#.#.#.#.....#...#.........#.#...#.........#.#.#.....#.#.#.#...#.#.#.........#.#.#.#...#...#...#.#.# + ###.###.#.###.#.###.#.#.#.#####.#.###.###.###.#####.#######.#######.#####.#.#.#.###.#.#.###.#######.#.#.#.#.#####.#.#.# + #...#.....#.........#.#.#.#.........#.#.#.#.#.#.#.....#.....#.......#.#.....#...........#.....#.#.#...#.#.#...#...#.#.# + ###.#.###.#####.#########.###.###.#####.#.#.###.#.#.###.#########.#.#.#####.###.###.###########.#.###.#.###.#####.#.#.# + #.#...#.#...#.#.#...#.#.#.#...#.....#.....#.#.....#.#...#...#.....#.#.......#.....#.#.#.#.#...#.....#...#.....#.....#.# + #.#####.#.###.#.#.###.#.#.#######.#####.#.#.#####.###.#.#.#.###.#####.#########.###.#.#.#.#.###.#####.###.#########.#.# + #.#...#.......#.#.#.....#...........#...#.#.#.#.....#.#...#...#.....#.........#.#.....#.....#.....#...........#.......# + #.#.#######.###.#.###.#.#########.#######.#.#.###.#.#####.#.#.#####.#######.#.###.#######.#.###.#########.#.#####.#.### + #...#...#.#.#.#...#...#.#...#.#.........#.....#...#...#...#.#.#.....#.......#...#.....#...#.#.#...#.#.#...#.#...#.#.#.# + ###.###.#.#.#.#.#####.#####.#.#######.###.###########.#######.#.#####.#############.#######.#.#.###.#.###.#####.###.#.# + #.#.#.#...#...#.#...#.#...#...# E X K R X V W #.........#...#...#...#.#...#.# + #.#.#.#.#####.#.#.###.#.###.### N I H F B M D #.###.#######.#.#.###.#.#.###.# + #.....#.....#...........#.....# #.#.....#.....#.#.#.#.#.......# + #.###.#.###.#.#####.#.#.#.###.# #####.#######.#.###.#.###.#.### + #.#...#...#...#.....#.#.#...#..UO QA..#.............#.#.......#.#..MB + #.#.#####.###.###.#.#.#.#.#.### #.#.#.#.###.###.#.#.###.#####.# +HV..#.....#.#.....#.#.#.#.#.#...# #...#.#.#.....#...#.#...#.....# + #######.#.#.#####.#.###.#####.# #########.#.###.#.#.#.#####.#.# + #.#...#...#.#.#...#.#.#.......# #.....#...#.#.#.#...#.#.....#.# + #.#.#########.#######.######### ###.#########.#.#.###.#.#.#.#.# + #.......#...#.......#.....#...# #...#.......#.#.#...#...#.#.#..ZZ + #.#.#.#.#.#.#.#.###.#.###.#.#.# ###.#####.###.#.#.###.#.####### + #.#.#.#...#.#.#.#...#.#.....#.# #...#.#.#.#...#.#.#...#.#.#.#..YX + #.#####.#.#.#.#.#.###.#######.# #.#.#.#.#.#.#.#.#########.#.#.# + #.....#.#.#...#.#.#...#.#.....# GT..#.....#...#.#...#.....#.....# + #.#.#############.###.#.###.### #.#.#.#.#.###.#######.###.#.#.# +XI..#.#.#...#.#...#.......#......AO #.#.#.#...#...#.#.#...#.#.#.#.# + #.#.#.###.#.###.#######.###.#.# ###.#####.#.###.#.###.#.#.##### + #.#.#.......#.........#.#.#.#.# #...#.#...#.................#.# + #####.###.###.#####.#.###.#.### ###.#.###.#.###.#.###.#######.# +WD......#...........#.#.....#.#.# #.#.#.....#.#.#.#.#.#.#...#....AO + #.###.#####.#.###########.###.# #.#########.#.###.#.###.#.#.### + #.#.....#...#...#.........#...# #...#.........#.#.#.#...#.#...# + #.#########.#.#######.#####.#.# #.#############.###.#.#.#.#.#.# + #...#...#.#.#.#...#.........#..MB PI..#...#.#.#.#...#.....#.#.#.#.# + #######.#.#.#####.#.###.#.#.### #.###.#.#.#.#.#####.#.###.###.# + #...#.....#.#.#.#.#...#.#.#.#..UY #...................#.#.......# + #.###.#######.#.#.###########.# #######.####################### +ZY....#...#.....#.#.#.#..........HV RU......#.#...............#...#..PI + #.#.#.#####.#.#.#.#.#####.#.### #####.###.###.###.###.#.#.#.#.# + #.#.....#...#.........#...#...# #...#.#...#.....#.#.#.#...#...# + #.###.#####.###.###.###.###.#.# #.###.#.###.###.#.#.#.#.####### +OQ..#.#.......#.#...#.......#.#.# #.#...#...#...#.#...#.#.....#.# + ###.#########.###############.# ###.###.#####.#########.#####.# + #...............#.#.......#...# #.......#...#...#.#...#.#.#...# + #.###.#####.#####.#.#####.##### ###########.#####.###.###.#.### + #.#.#.....#...#.#.....#.....#.# #.............#.#...........#.# + ###.###.###.###.#####.#.#####.# #.###.###.#.###.###.#.#####.#.# + #.....#.#...#.#.#.....#.......# OQ..#.....#.#.#.#.....#.....#.#..WA + #.###.#.#.###.#.#.#########.### #.#.#########.#####.#######.#.# +UO..#.#...#.............#.#.#....SX #.#.....#.#...#...#...#.....#.# + ###.###############.###.#.##### ###.###.#.###.###.#.#######.#.# + #.......#.........#.#...#.....# #.#.#.#.............#.#.......# + #.#.#.#.#.#.###.#.###.#.#.###.# #.###.#####.#.###.#.#.#######.# + #.#.#.#...#...#.#.....#.....#..BY WA....#.....#.#.#...#...#...#.#.# + #.###############.#######.###.# ###.#.###.###.#########.###.### +RF....#.#.#...#.....#.#.#...#.#.# #...#.#...#.......#...#.#.#.#.# + #####.#.###.#######.#.#####.### #.###.###.###.#####.###.#.#.#.# + #.#.#.#.................#.#....TR #.....#.....#...#.#.....#.#...# + #.#.#.#.#.#.#.###.#.###.#.###.# #.###.###.#######.#.#.###.#.### +XB....#...#.#.#.#...#.#.........# #...#.#.#...........#..........KH + ###.#.#.#.#.#####.#####.#.#.### #.#####.#.###.#.#.#.###.#.###.# + #...#.#.#.#.#.....#.#...#.#...# #...#.......#.#.#.#.#.#.#.#...# + ###.#.#####.###.#.#.#.#.#.#.### ###.###.#####.#.###.#.#.#####.# + #.......#.....#.#...#.#.#.#...# #...#.....#.#.#...#.#.......#.# + ###.#.#####.#.###.#.#####.###.# Z M Y M P L #.#.#.#.###.#.#.###.#.#.####### + #...#.#...#.#.#...#...#...#...# Y W X D S G #.#.#.#.#.....#...#.#.#.......# + ###.###.#########.#########################.#######.###.###########.#######.###.###########.###.#.#.#.###.#####.###.### + #.........#...#.......#.#.......#.....#...#.#.#...#.#.........#.......#.#.#.#...#.......#.#...#.#.#.#...#.....#...#...# + #.###.#####.###.#.#.###.###.#########.#.#.#.#.#.#.#.#.#.#.###.###.#.###.#.#.#.#####.#.###.#.#####.###.###.#####.#.#.### + #.#.........#...#.#.#.........#.#.#.....#...#...#...#.#.#...#.#.#.#...#.#...#.....#.#.....#...#.#.#.#.#.#.....#.#.#...# + #####.#.###.#.###.#########.#.#.#.#.###.#####.#.#####.#########.###.###.###.###.###.#.#######.#.###.#.#.###.#####.#.### + #.#...#...#.#.#.....#.#.#...#.#.....#.....#.#.#.#...........#.....#.....#.#.#...#.#.#.#...#.#.#...........#...#...#...# + #.#.#.#.#.###########.#.#.#.###.#.#######.#.#.#######.#.#######.###.#.###.#.#.###.#.###.###.###.###.#####.#.#.###.###.# + #.#.#.#.#.........#.....#.#.#.#.#.#.........#...#.....#.#.#...#.#...#.#.#...#.......#.........#...#...#...#.#...#.#...# + #.#.###.#######.#######.###.#.#.#######.#######.#######.#.#.#.#.#.#####.#.###.###.#.#.###.#########.###.#.#.#####.###.# + #...#.........#.#...#.........#.#.#.....#.#.#.....#.......#.#.#.....#.......#...#.#.....#...#.#...#.#.#.#.#...#.....#.# + ###.#.#########.#.#######.#.#.###.###.#.#.#.#.###.#.#.#######.#.#####.#.#.#.#######.###.#.###.#.###.#.###.#.###.#.###.# + #.#.#.#...#...#.#.#.#.#...#.#.........#.#.....#.#.#.#...#.#.........#.#.#.#.#.........#.#.#...#.#.......#.#...#.#.#...# + #.#.###.#####.###.#.#.###.#####.#####.###.###.#.#####.###.#.#.#####.#######.#####.###########.#.###.#######.#####.###.# + #.....#.........#.........#.....#.......#.#.#.....#.#...#.#.#...#.#...#.....#.......#.......#.....#...#.......#.....#.# + #####.#.###.###########.#####.###.###.###.#.#.#####.#.###.#.#.###.#.#######.#####.###.#.#.###.###.#.#####.#.#.###.#.### + #.........#...#.#.......#.#...#...#.....#.#...#...........#.#...#.#.#.#.......#.#.....#.#.#.#...#.#.#...#.#.#...#.#...# + #.###.#########.#.#####.#.###.#.#####.###.#.#.#######.#######.#.#.###.###.###.#.#.#########.#.#####.#.#####.#####.###.# + #...#.......#.....#.#...#.....#.#.......#.#.#...#.....#.......#.#.......#...#.#.#.#.#...........#.......#.#...#...#...# + #.#.###.###.#.#####.###########.#####.#.#####.#######.###.###.#########.#.#####.#.#.#.#.###########.#####.#.#.#.#.#.### + #.#.#...#...#.#.........#.#...#.#.#.#.#.#...........#...#.#.#...#...........#.........#.....#...#.........#.#.#.#.#...# + #.#.#.###.#############.#.#.#####.#.#.###.#.#.#########.###.#.#############.#.#####.###.#####.###.#.#.###.###.#######.# + #.#.#...#.#.#.#.#.....#.#.#.#...#.......#.#.#.#.#.....#.....#...#.#.#...#...#...#...#.#.#.#.....#.#.#...#.#.........#.# + ###.#.#.###.#.#.#####.#.#.#.###.#####.#.#####.#.#.###.#####.#.###.#.#.###.#.###.#####.###.#.#########.#.###.###.###.#.# + #.#.#.#.#.....#.#.....................#...#.....#.#.#.......#...#...#...#.#.#.......#...............#.#.#.....#...#.#.# + #.#.#########.#.#.#.#.###.#####.#.###.#######.#####.###.#####.#####.#.#.#.#.#.#######.###.#.###.###.###########.#####.# + #.....#...#.......#.#.#.....#.#.#.#.....#.#.#.#.....#.#.#.#.#...#.....#...#.#.........#.#.#.#...#.....#.......#...#...# + #.#######.#.#####.###.#######.#######.###.#.#.###.###.#.#.#.###.#####.###.###.#########.#.###.#.#####.#.#######.#.###.# + #.#...#...#.#.....#...#.............#.#.....#.......#.....#.#.......#.#.#.#.............#...#.#...#.......#.#.#.#...#.# + #.#.#.#.#.#.#####.###.#####.#######.#.#.#.#########.#.#####.#######.#.#.#####.###############.#.#.#.###.###.#.#####.### + #.#.#...#.....#...#...#.....#...........#.....#.....#.......#.......#...#...................#.#.#.#...#...........#...# + ###########################################.###.#########.#######.#####.#########.##################################### + M T P Q M E + W R S A D N diff --git a/day20/prompt.txt b/day20/prompt.txt new file mode 100644 index 0000000..c7435fa --- /dev/null +++ b/day20/prompt.txt @@ -0,0 +1,74 @@ +--- Day 20: Donut Maze --- +You notice a strange pattern on the surface of Pluto and land nearby to get a closer look. Upon closer inspection, you realize you've come across one of the famous space-warping mazes of the long-lost Pluto civilization! + +Because there isn't much space on Pluto, the civilization that used to live here thrived by inventing a method for folding spacetime. Although the technology is no longer understood, mazes like this one provide a small glimpse into the daily life of an ancient Pluto citizen. + +This maze is shaped like a donut. Portals along the inner and outer edge of the donut can instantly teleport you from one side to the other. For example: + + A + A + #######.######### + #######.........# + #######.#######.# + #######.#######.# + #######.#######.# + ##### B ###.# +BC...## C ###.# + ##.## ###.# + ##...DE F ###.# + ##### G ###.# + #########.#####.# +DE..#######...###.# + #.#########.###.# +FG..#########.....# + ###########.##### + Z + Z +This map of the maze shows solid walls (#) and open passages (.). Every maze on Pluto has a start (the open tile next to AA) and an end (the open tile next to ZZ). Mazes on Pluto also have portals; this maze has three pairs of portals: BC, DE, and FG. When on an open tile next to one of these labels, a single step can take you to the other tile with the same label. (You can only walk on . tiles; labels and empty space are not traversable.) + +One path through the maze doesn't require any portals. Starting at AA, you could go down 1, right 8, down 12, left 4, and down 1 to reach ZZ, a total of 26 steps. + +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. + +Here is a larger example: + + A + A + #################.############# + #.#...#...................#.#.# + #.#.#.###.###.###.#########.#.# + #.#.#.......#...#.....#.#.#...# + #.#########.###.#####.#.#.###.# + #.............#.#.....#.......# + ###.###########.###.#####.#.#.# + #.....# A C #.#.#.# + ####### S P #####.# + #.#...# #......VT + #.#.#.# #.##### + #...#.# YN....#.# + #.###.# #####.# +DI....#.# #.....# + #####.# #.###.# +ZZ......# QG....#..AS + ###.### ####### +JO..#.#.# #.....# + #.#.#.# ###.#.# + #...#..DI BU....#..LF + #####.# #.##### +YN......# VT..#....QG + #.###.# #.###.# + #.#...# #.....# + ###.### J L J #.#.### + #.....# O F P #.#...# + #.###.#####.#.#####.#####.###.# + #...#.#.#...#.....#.....#.#...# + #.#####.###.###.#.#.#########.# + #...#.#.....#...#.#.#.#.....#.# + #.###.#####.###.###.#.#.####### + #.#.........#...#.............# + #########.###.###.############# + B J C + 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. + +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/day22/input.txt b/day22/input.txt new file mode 100644 index 0000000..d99fbe6 --- /dev/null +++ b/day22/input.txt @@ -0,0 +1,100 @@ +deal into new stack +deal with increment 21 +cut -1639 +deal with increment 32 +cut -873 +deal with increment 8 +deal into new stack +cut -7730 +deal with increment 8 +cut -8408 +deal with increment 42 +cut -4951 +deal into new stack +deal with increment 24 +cut -6185 +deal with increment 69 +cut -930 +deal into new stack +cut 8675 +deal with increment 47 +cut -4543 +deal with increment 62 +deal into new stack +deal with increment 23 +cut 7128 +deal with increment 29 +deal into new stack +deal with increment 65 +cut 8232 +deal with increment 34 +deal into new stack +deal with increment 7 +deal into new stack +cut -5590 +deal with increment 34 +cut -3523 +deal with increment 24 +cut 8446 +deal with increment 42 +cut 6714 +deal into new stack +deal with increment 60 +cut 1977 +deal with increment 51 +cut 2719 +deal with increment 45 +cut 9563 +deal with increment 33 +cut 9036 +deal with increment 70 +cut 3372 +deal with increment 60 +cut 9686 +deal with increment 7 +cut 9344 +deal with increment 13 +cut 797 +deal with increment 12 +cut -6989 +deal with increment 43 +deal into new stack +cut 1031 +deal with increment 14 +cut -1145 +deal with increment 26 +cut -9008 +deal with increment 14 +cut 432 +deal with increment 46 +cut -65 +deal with increment 50 +cut -704 +deal with increment 4 +cut 7372 +deal with increment 66 +cut 690 +deal with increment 60 +cut -7137 +deal with increment 66 +cut 9776 +deal with increment 30 +cut 3532 +deal with increment 62 +cut 4768 +deal with increment 13 +deal into new stack +cut -9014 +deal with increment 68 +cut -9601 +deal with increment 6 +cut -7535 +deal with increment 74 +cut 9479 +deal with increment 6 +cut -1879 +deal with increment 33 +cut 3675 +deal with increment 19 +cut -937 +deal with increment 42 diff --git a/day22/prompt.txt b/day22/prompt.txt new file mode 100644 index 0000000..5380ac9 --- /dev/null +++ b/day22/prompt.txt @@ -0,0 +1,135 @@ +--- Day 22: Slam Shuffle --- +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 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 on the bottom. + +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 of the new stack repeatedly until you run out of cards: + +Top Bottom +0 1 2 3 4 5 6 7 8 9 Your deck + New stack + + 1 2 3 4 5 6 7 8 9 Your deck + 0 New stack + + 2 3 4 5 6 7 8 9 Your deck + 1 0 New stack + + 3 4 5 6 7 8 9 Your deck + 2 1 0 New stack + +Several steps later... + + 9 Your deck + 8 7 6 5 4 3 2 1 0 New stack + + Your deck +9 8 7 6 5 4 3 2 1 0 New stack +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 bottom of the deck, retaining their order. For example, to cut 3: + +Top Bottom +0 1 2 3 4 5 6 7 8 9 Your deck + + 3 4 5 6 7 8 9 Your deck +0 1 2 Cut cards + +3 4 5 6 7 8 9 Your deck + 0 1 2 Cut cards + +3 4 5 6 7 8 9 0 1 2 Your deck +You've also been getting pretty good at a version of this technique where N is negative! In that case, cut (the absolute value of) N cards from the bottom of the deck onto the top. For example, to cut -4: + +Top Bottom +0 1 2 3 4 5 6 7 8 9 Your deck + +0 1 2 3 4 5 Your deck + 6 7 8 9 Cut cards + + 0 1 2 3 4 5 Your deck +6 7 8 9 Cut cards + +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 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 process until you run out of cards. + +For example, to deal with increment 3: + + +0 1 2 3 4 5 6 7 8 9 Your deck +. . . . . . . . . . Space on table +^ Current position + +Deal the top card to the current position: + + 1 2 3 4 5 6 7 8 9 Your deck +0 . . . . . . . . . Space on table +^ Current position + +Move the current position right 3: + + 1 2 3 4 5 6 7 8 9 Your deck +0 . . . . . . . . . Space on table + ^ Current position + +Deal the top card: + + 2 3 4 5 6 7 8 9 Your deck +0 . . 1 . . . . . . Space on table + ^ Current position + +Move right 3 and deal: + + 3 4 5 6 7 8 9 Your deck +0 . . 1 . . 2 . . . Space on table + ^ Current position + +Move right 3 and deal: + + 4 5 6 7 8 9 Your deck +0 . . 1 . . 2 . . 3 Space on table + ^ Current position + +Move right 3, wrapping around, and deal: + + 5 6 7 8 9 Your deck +0 . 4 1 . . 2 . . 3 Space on table + ^ Current position + +And so on: + +0 7 4 1 8 5 2 9 6 3 Space on table +Positions on the table which already contain cards are still counted; they're not skipped. Of course, this technique is carefully designed so it will never put two cards in the same position or leave a position empty. + +Finally, collect the cards on the table so that the leftmost card ends up at the top of your deck, the card to its right ends up just below the top card, and so on, until the rightmost card ends up 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 cards: + +deal with increment 7 +deal into new stack +deal into new stack +Result: 0 3 6 9 2 5 8 1 4 7 +cut 6 +deal with increment 7 +deal into new stack +Result: 3 0 7 4 1 8 5 2 9 6 +deal with increment 7 +deal with increment 9 +cut -2 +Result: 6 3 0 7 4 1 8 5 2 9 +deal into new stack +cut -2 +deal with increment 7 +cut 8 +cut -4 +deal with increment 7 +cut 3 +deal with increment 9 +deal with increment 3 +cut -1 +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? diff --git a/day24/input.txt b/day24/input.txt new file mode 100644 index 0000000..f6734f2 --- /dev/null +++ b/day24/input.txt @@ -0,0 +1,5 @@ +#.#.# +.#... +...#. +.###. +###.# diff --git a/day24/prompt.txt b/day24/prompt.txt new file mode 100644 index 0000000..b2c7d9f --- /dev/null +++ b/day24/prompt.txt @@ -0,0 +1,57 @@ +--- Day 24: Planet of Discord --- +You land on Eris, your last stop before reaching Santa. As soon as you do, your sensors start picking up strange life forms moving around: Eris is infested with bugs! With an over 24-hour 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 (.). + +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. +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 tile first, and then the tiles are updated. + +Here are the first few minutes of an example scenario: + +Initial state: +....# +#..#. +#..## +..#.. +#.... + +After 1 minute: +#..#. +####. +###.# +##.## +.##.. + +After 2 minutes: +##### +....# +....# +...#. +#.### + +After 3 minutes: +#.... +####. +...## +#.##. +.##.# + +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: + +..... +..... +..... +#.... +.#... +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 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. + +What is the biodiversity rating for the first layout that appears twice?