From 8e5e6a54fde9c52113ab7d85787b41e27868fa59 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Mon, 23 Dec 2024 07:29:26 -0600 Subject: [PATCH] Adding some problems --- 2024/day21/problem | 215 +++++++++++++++++++++++++++++++++++++++++ 2024/day22/problem | 236 +++++++++++++++++++++++++++++++++++++++++++++ 2024/day23/problem | 150 ++++++++++++++++++++++++++++ 3 files changed, 601 insertions(+) create mode 100644 2024/day21/problem create mode 100644 2024/day22/problem create mode 100644 2024/day23/problem diff --git a/2024/day21/problem b/2024/day21/problem new file mode 100644 index 0000000..ec72268 --- /dev/null +++ b/2024/day21/problem @@ -0,0 +1,215 @@ +Advent of Code + +--- Day 21: Keypad Conundrum --- + + As you teleport onto Santa's [16]Reindeer-class starship, The Historians + begin to panic: someone from their search party is missing. A quick + life-form scan by the ship's computer reveals that when the missing + Historian teleported, he arrived in another part of the ship. + + The door to that area is locked, but the computer can't open it; it can + only be opened by physically typing the door codes (your puzzle input) on + the numeric keypad on the door. + + The numeric keypad has four rows of buttons: 789, 456, 123, and finally an + empty gap followed by 0A. Visually, they are arranged like this: + + +---+---+---+ + | 7 | 8 | 9 | + +---+---+---+ + | 4 | 5 | 6 | + +---+---+---+ + | 1 | 2 | 3 | + +---+---+---+ + | 0 | A | + +---+---+ + + Unfortunately, the area outside the door is currently depressurized and + nobody can go near the door. A robot needs to be sent instead. + + The robot has no problem navigating the ship and finding the numeric + keypad, but it's not designed for button pushing: it can't be told to push + a specific button directly. Instead, it has a robotic arm that can be + controlled remotely via a directional keypad. + + The directional keypad has two rows of buttons: a gap / ^ (up) / A + (activate) on the first row and < (left) / v (down) / > (right) on the + second row. Visually, they are arranged like this: + + +---+---+ + | ^ | A | + +---+---+---+ + | < | v | > | + +---+---+---+ + + When the robot arrives at the numeric keypad, its robotic arm is pointed + at the A button in the bottom right corner. After that, this directional + keypad remote control must be used to maneuver the robotic arm: the up / + down / left / right buttons cause it to move its arm one button in that + direction, and the A button causes the robot to briefly move forward, + pressing the button being aimed at by the robotic arm. + + For example, to make the robot type 029A on the numeric keypad, one + sequence of inputs on the directional keypad you could use is: + + • < to move the arm from A (its initial position) to 0. + • A to push the 0 button. + • ^A to move the arm to the 2 button and push it. + • >^^A to move the arm to the 9 button and push it. + • vvvA to move the arm to the A button and push it. + + In total, there are three shortest possible sequences of button presses on + this directional keypad that would cause the robot to type 029A: + ^^AvvvA, ^AvvvA, and AvvvA. + + Unfortunately, the area containing this directional keypad remote control + is currently experiencing high levels of radiation and nobody can go near + it. A robot needs to be sent instead. + + When the robot arrives at the directional keypad, its robot arm is pointed + at the A button in the upper right corner. After that, a second, different + directional keypad remote control is used to control this robot (in the + same way as the first robot, except that this one is typing on a + directional keypad instead of a numeric keypad). + + There are multiple shortest possible sequences of directional keypad + button presses that would cause this robot to tell the first robot to type + 029A on the door. One such sequence is v<>^AAvA<^AA>A^A. + + Unfortunately, the area containing this second directional keypad remote + control is currently -40 degrees! Another robot will need to be sent to + type on that directional keypad, too. + + There are many shortest possible sequences of directional keypad button + presses that would cause this robot to tell the second robot to tell the + first robot to eventually type 029A on the door. One such sequence is + >^AvAA<^A>A>^AvA^A^A^A>AAvA^AA>^AAAvA<^A>A. + + Unfortunately, the area containing this third directional keypad remote + control is currently full of Historians, so no robots can find a clear + path there. Instead, you will have to type this sequence yourself. + + Were you to choose this sequence of button presses, here are all of the + buttons that would be pressed on your directional keypad, the two robots' + directional keypads, and the numeric keypad: + + >^AvAA<^A>A>^AvA^A^A^A>AAvA^AA>^AAAvA<^A>A + v<>^AAvA<^AA>A^A + ^^AvvvA + 029A + + In summary, there are the following keypads: + + • One directional keypad that you are using. + • Two directional keypads that robots are using. + • One numeric keypad (on a door) that a robot is using. + + It is important to remember that these robots are not designed for button + pushing. In particular, if a robot arm is ever aimed at a gap where no + button is present on the keypad, even for an instant, the robot will panic + unrecoverably. So, don't do that. All robots will initially aim at the + keypad's A key, wherever it is. + + To unlock the door, five codes will need to be typed on its numeric + keypad. For example: + + 029A + 980A + 179A + 456A + 379A + + For each of these, here is a shortest sequence of button presses you could + type to cause the desired code to be typed on the numeric keypad: + + 029A: >^AvAA<^A>A>^AvA^A^A^A>AAvA^AA>^AAAvA<^A>A + 980A: >^AAAvA^A>^AvAA<^A>AA>^AAAvA<^A>A^AA + 179A: >^A>^AAvAA<^A>A>^AAvA^A^AAAA>^AAAvA<^A>A + 456A: >^AA>^AAvAA<^A>A^AA^AAA>^AAvA<^A>A + 379A: >^AvA^A>^AAvA<^A>AAvA^A^AAAA>^AAAvA<^A>A + + The Historians are getting nervous; the ship computer doesn't remember + whether the missing Historian is trapped in the area containing a giant + electromagnet or molten lava. You'll need to make sure that for each of + the five codes, you find the shortest sequence of button presses + necessary. + + The complexity of a single code (like 029A) is equal to the result of + multiplying these two values: + + • The length of the shortest sequence of button presses you need to type + on your directional keypad in order to cause the code to be typed on + the numeric keypad; for 029A, this would be 68. + • The numeric part of the code (ignoring leading zeroes); for 029A, this + would be 29. + + In the above example, complexity of the five codes can be found by + calculating 68 * 29, 60 * 980, 68 * 179, 64 * 456, and 64 * 379. Adding + these together produces 126384. + + Find the fewest number of button presses you'll need to perform in order + to cause the robot in front of the door to type each code. What is the sum + of the complexities of the five codes on your list? + + Your puzzle answer was 248684. + +--- Part Two --- + + Just as the missing Historian is released, The Historians realize that a + second member of their search party has also been missing this entire + time! + + A quick life-form scan reveals the Historian is also trapped in a locked + area of the ship. Due to a variety of hazards, robots are once again + dispatched, forming another chain of remote control keypads managing + robotic-arm-wielding robots. + + This time, many more robots are involved. In summary, there are the + following keypads: + + • One directional keypad that you are using. + • 25 directional keypads that robots are using. + • One numeric keypad (on a door) that a robot is using. + + The keypads form a chain, just like before: your directional keypad + controls a robot which is typing on a directional keypad which controls a + robot which is typing on a directional keypad... and so on, ending with + the robot which is typing on the numeric keypad. + + The door codes are the same this time around; only the number of robots + and directional keypads has changed. + + Find the fewest number of button presses you'll need to perform in order + to cause the robot in front of the door to type each code. What is the sum + of the complexities of the five codes on your list? + + Your puzzle answer was 307055584161760. + + Both parts of this puzzle are complete! They provide two gold stars: ** + + At this point, you should [17]return to your Advent calendar and try + another puzzle. + + If you still want to see it, you can [18]get your puzzle input. + +References + + Visible links + 1. https://adventofcode.com/ + 2. https://adventofcode.com/2024/about + 3. https://adventofcode.com/2024/events + 4. https://cottonbureau.com/people/advent-of-code + 5. https://adventofcode.com/2024/settings + 6. https://adventofcode.com/2024/auth/logout + 7. Advent of Code Supporter + https://adventofcode.com/2024/support + 8. https://adventofcode.com/2024 + 9. https://adventofcode.com/2024 + 10. https://adventofcode.com/2024/support + 11. https://adventofcode.com/2024/sponsors + 12. https://adventofcode.com/2024/leaderboard + 13. https://adventofcode.com/2024/stats + 14. https://adventofcode.com/2024/sponsors + 16. https://adventofcode.com/2019/day/25 + 17. https://adventofcode.com/2024 + 18. https://adventofcode.com/2024/day/21/input diff --git a/2024/day22/problem b/2024/day22/problem new file mode 100644 index 0000000..bff40da --- /dev/null +++ b/2024/day22/problem @@ -0,0 +1,236 @@ +Advent of Code + +--- Day 22: Monkey Market --- + + As you're all teleported deep into the jungle, a [16]monkey steals The + Historians' device! You'll need to get it back while The Historians are + looking for the Chief. + + The monkey that stole the device seems willing to trade it, but only in + exchange for an absurd number of bananas. Your only option is to buy + bananas on the Monkey Exchange Market. + + You aren't sure how the Monkey Exchange Market works, but one of The + Historians senses trouble and comes over to help. Apparently, they've been + studying these monkeys for a while and have deciphered their secrets. + + Today, the Market is full of monkeys buying good hiding spots. + Fortunately, because of the time you recently spent in this jungle, you + know lots of good hiding spots you can sell! If you sell enough hiding + spots, you should be able to get enough bananas to buy the device back. + + On the Market, the buyers seem to use random prices, but their prices are + actually only [17]pseudorandom! If you know the secret of how they pick + their prices, you can wait for the perfect time to sell. + + The part about secrets is literal, the Historian explains. Each buyer + produces a pseudorandom sequence of secret numbers where each secret is + derived from the previous. + + In particular, each buyer's secret number evolves into the next secret + number in the sequence via the following process: + + • Calculate the result of multiplying the secret number by 64. Then, mix + this result into the secret number. Finally, prune the secret number. + • Calculate the result of dividing the secret number by 32. Round the + result down to the nearest integer. Then, mix this result into the + secret number. Finally, prune the secret number. + • Calculate the result of multiplying the secret number by 2048. Then, + mix this result into the secret number. Finally, prune the secret + number. + + Each step of the above process involves mixing and pruning: + + • To mix a value into the secret number, calculate the [18]bitwise XOR + of the given value and the secret number. Then, the secret number + becomes the result of that operation. (If the secret number is 42 and + you were to mix 15 into the secret number, the secret number would + become 37.) + • To prune the secret number, calculate the value of the secret number + [19]modulo 16777216. Then, the secret number becomes the result of + that operation. (If the secret number is 100000000 and you were to + prune the secret number, the secret number would become 16113920.) + + After this process completes, the buyer is left with the next secret + number in the sequence. The buyer can repeat this process as many times as + necessary to produce more secret numbers. + + So, if a buyer had a secret number of 123, that buyer's next ten secret + numbers would be: + + 15887950 + 16495136 + 527345 + 704524 + 1553684 + 12683156 + 11100544 + 12249484 + 7753432 + 5908254 + + Each buyer uses their own secret number when choosing their price, so it's + important to be able to predict the sequence of secret numbers for each + buyer. Fortunately, the Historian's research has uncovered the initial + secret number of each buyer (your puzzle input). For example: + + 1 + 10 + 100 + 2024 + + This list describes the initial secret number of four different + secret-hiding-spot-buyers on the Monkey Exchange Market. If you can + simulate secret numbers from each buyer, you'll be able to predict all of + their future prices. + + In a single day, buyers each have time to generate 2000 new secret + numbers. In this example, for each buyer, their initial secret number and + the 2000th new secret number they would generate are: + + 1: 8685429 + 10: 4700978 + 100: 15273692 + 2024: 8667524 + + Adding up the 2000th new secret number for each buyer produces 37327623. + + For each buyer, simulate the creation of 2000 new secret numbers. What is + the sum of the 2000th secret number generated by each buyer? + + Your puzzle answer was 14082561342. + +--- Part Two --- + + Of course, the secret numbers aren't the prices each buyer is offering! + That would be ridiculous. Instead, the prices the buyer offers are just + the ones digit of each of their secret numbers. + + So, if a buyer starts with a secret number of 123, that buyer's first ten + prices would be: + + 3 (from 123) + 0 (from 15887950) + 6 (from 16495136) + 5 (etc.) + 4 + 4 + 6 + 4 + 4 + 2 + + This price is the number of bananas that buyer is offering in exchange for + your information about a new hiding spot. However, you still don't speak + [20]monkey, so you can't negotiate with the buyers directly. The Historian + speaks a little, but not enough to negotiate; instead, he can ask another + monkey to negotiate on your behalf. + + Unfortunately, the monkey only knows how to decide when to sell by looking + at the changes in price. Specifically, the monkey will only look for a + specific sequence of four consecutive changes in price, then immediately + sell when it sees that sequence. + + So, if a buyer starts with a secret number of 123, that buyer's first ten + secret numbers, prices, and the associated changes would be: + + 123: 3 + 15887950: 0 (-3) + 16495136: 6 (6) + 527345: 5 (-1) + 704524: 4 (-1) + 1553684: 4 (0) + 12683156: 6 (2) + 11100544: 4 (-2) + 12249484: 4 (0) + 7753432: 2 (-2) + + Note that the first price has no associated change because there was no + previous price to compare it with. + + In this short example, within just these first few prices, the highest + price will be 6, so it would be nice to give the monkey instructions that + would make it sell at that time. The first 6 occurs after only two + changes, so there's no way to instruct the monkey to sell then, but the + second 6 occurs after the changes -1,-1,0,2. So, if you gave the monkey + that sequence of changes, it would wait until the first time it sees that + sequence and then immediately sell your hiding spot information at the + current price, winning you 6 bananas. + + Each buyer only wants to buy one hiding spot, so after the hiding spot is + sold, the monkey will move on to the next buyer. If the monkey never hears + that sequence of price changes from a buyer, the monkey will never sell, + and will instead just move on to the next buyer. + + Worse, you can only give the monkey a single sequence of four price + changes to look for. You can't change the sequence between buyers. + + You're going to need as many bananas as possible, so you'll need to + determine which sequence of four price changes will cause the monkey to + get you the most bananas overall. Each buyer is going to generate 2000 + secret numbers after their initial secret number, so, for each buyer, + you'll have 2000 price changes in which your sequence can occur. + + Suppose the initial secret number of each buyer is: + + 1 + 2 + 3 + 2024 + + There are many sequences of four price changes you could tell the monkey, + but for these four buyers, the sequence that will get you the most bananas + is -2,1,-1,3. Using that sequence, the monkey will make the following + sales: + + • For the buyer with an initial secret number of 1, changes -2,1,-1,3 + first occur when the price is 7. + • For the buyer with initial secret 2, changes -2,1,-1,3 first occur + when the price is 7. + • For the buyer with initial secret 3, the change sequence -2,1,-1,3 + does not occur in the first 2000 changes. + • For the buyer starting with 2024, changes -2,1,-1,3 first occur when + the price is 9. + + So, by asking the monkey to sell the first time each buyer's prices go + down 2, then up 1, then down 1, then up 3, you would get 23 (7 + 7 + 9) + bananas! + + Figure out the best sequence to tell the monkey so that by looking for + that same sequence of changes in every buyer's future prices, you get the + most bananas in total. What is the most bananas you can get? + + Your puzzle answer was 1568. + + Both parts of this puzzle are complete! They provide two gold stars: ** + + At this point, you should [21]return to your Advent calendar and try + another puzzle. + + If you still want to see it, you can [22]get your puzzle input. + +References + + Visible links + 1. https://adventofcode.com/ + 2. https://adventofcode.com/2024/about + 3. https://adventofcode.com/2024/events + 4. https://cottonbureau.com/people/advent-of-code + 5. https://adventofcode.com/2024/settings + 6. https://adventofcode.com/2024/auth/logout + 7. Advent of Code Supporter + https://adventofcode.com/2024/support + 8. https://adventofcode.com/2024 + 9. https://adventofcode.com/2024 + 10. https://adventofcode.com/2024/support + 11. https://adventofcode.com/2024/sponsors + 12. https://adventofcode.com/2024/leaderboard + 13. https://adventofcode.com/2024/stats + 14. https://adventofcode.com/2024/sponsors + 16. https://adventofcode.com/2022/day/11 + 17. https://en.wikipedia.org/wiki/Pseudorandom_number_generator + 18. https://en.wikipedia.org/wiki/Bitwise_operation#XOR + 19. https://en.wikipedia.org/wiki/Modulo + 20. https://adventofcode.com/2022/day/21 + 21. https://adventofcode.com/2024 + 22. https://adventofcode.com/2024/day/22/input diff --git a/2024/day23/problem b/2024/day23/problem new file mode 100644 index 0000000..9b54517 --- /dev/null +++ b/2024/day23/problem @@ -0,0 +1,150 @@ +[1]Advent of Code + +--- Day 23: LAN Party --- + + As The Historians wander around a secure area at Easter Bunny HQ, you come + across posters for a [16]LAN party scheduled for today! Maybe you can find + it; you connect to a nearby [17]datalink port and download a map of the + local network (your puzzle input). + + The network map provides a list of every connection between two computers. + For example: + + kh-tc + qp-kh + de-cg + ka-co + yn-aq + qp-ub + cg-tb + vc-aq + tb-ka + wh-tc + yn-cg + kh-ub + ta-co + de-co + tc-td + tb-wq + wh-td + ta-ka + td-qp + aq-cg + wq-ub + ub-vc + de-ta + wq-aq + wq-vc + wh-yn + ka-de + kh-ta + co-tc + wh-qp + tb-vc + td-yn + + Each line of text in the network map represents a single connection; the + line kh-tc represents a connection between the computer named kh and the + computer named tc. Connections aren't directional; tc-kh would mean + exactly the same thing. + + LAN parties typically involve multiplayer games, so maybe you can locate + it by finding groups of connected computers. Start by looking for sets of + three computers where each computer in the set is connected to the other + two computers. + + In this example, there are 12 such sets of three inter-connected + computers: + + aq,cg,yn + aq,vc,wq + co,de,ka + co,de,ta + co,ka,ta + de,ka,ta + kh,qp,ub + qp,td,wh + tb,vc,wq + tc,td,wh + td,wh,yn + ub,vc,wq + + If the Chief Historian is here, and he's at the LAN party, it would be + best to know that right away. You're pretty sure his computer's name + starts with t, so consider only sets of three computers where at least one + computer's name starts with t. That narrows the list down to 7 sets of + three inter-connected computers: + + co,de,ta + co,ka,ta + de,ka,ta + qp,td,wh + tb,vc,wq + tc,td,wh + td,wh,yn + + Find all the sets of three inter-connected computers. How many contain at + least one computer with a name that starts with t? + + Your puzzle answer was 1485. + +--- Part Two --- + + There are still way too many results to go through them all. You'll have + to find the LAN party another way and go there yourself. + + Since it doesn't seem like any employees are around, you figure they must + all be at the LAN party. If that's true, the LAN party will be the largest + set of computers that are all connected to each other. That is, for each + computer at the LAN party, that computer will have a connection to every + other computer at the LAN party. + + In the above example, the largest set of computers that are all connected + to each other is made up of co, de, ka, and ta. Each computer in this set + has a connection to every other computer in the set: + + ka-co + ta-co + de-co + ta-ka + de-ta + ka-de + + The LAN party posters say that the password to get into the LAN party is + the name of every computer at the LAN party, sorted alphabetically, then + joined together with commas. (The people running the LAN party are clearly + a bunch of nerds.) In this example, the password would be co,de,ka,ta. + + What is the password to get into the LAN party? + + Your puzzle answer was cc,dz,ea,hj,if,it,kf,qo,sk,ug,ut,uv,wh. + + Both parts of this puzzle are complete! They provide two gold stars: ** + + At this point, you should [18]return to your Advent calendar and try + another puzzle. + + If you still want to see it, you can [19]get your puzzle input. + +References + + Visible links + 1. https://adventofcode.com/ + 2. https://adventofcode.com/2024/about + 3. https://adventofcode.com/2024/events + 4. https://cottonbureau.com/people/advent-of-code + 5. https://adventofcode.com/2024/settings + 6. https://adventofcode.com/2024/auth/logout + 7. Advent of Code Supporter + https://adventofcode.com/2024/support + 8. https://adventofcode.com/2024 + 9. https://adventofcode.com/2024 + 10. https://adventofcode.com/2024/support + 11. https://adventofcode.com/2024/sponsors + 12. https://adventofcode.com/2024/leaderboard + 13. https://adventofcode.com/2024/stats + 14. https://adventofcode.com/2024/sponsors + 16. https://en.wikipedia.org/wiki/LAN_party + 17. https://adventofcode.com/2016/day/9 + 18. https://adventofcode.com/2024 + 19. https://adventofcode.com/2024/day/23/input