AOCWAT 2025

[go to last puzzle] or [go back]

Day 1: Secret Entrance This one wasn't too hard; it was the first day, after all.
Part 1 and 2 are basically the same, just where part 1 rotates e.g. left by 58 once, part 2 rotates left by one 58 times.
Not a great algorithm, but eh
Day 2: Gift Shop Part 1 of this wasn't very complex; had to do some funny math to check for repeating numbers but that was basically it.
Part 2 did throw in some more complexity, but part 1's code was adaptable to it well enough.
Day 3: Lobby Part 1 of this got a brute-force solution: try every possible first digit with every possible end second digit.
Part 2 forced a more clever solution - I realized I didn't have to check every combo, as a larger first digit would always produce a bigger joltage; so I just had to check for the first largest number in range for each digit.
Day 4: Printing Department This one wasn't that bad with memory set up well; with the rows spaced out from eachother with a constant offset, I can just check e.g. 257 bytes back in memory and find the cell up and left in the grid.
Part 2 was just part 1 in a loop and removing rolls when counted.
Day 5: Cafeteria Part 1 wasn't too bad; scan the ranges into memory, then check each ingredient against all ranges until one works.
Part 2 was way harder, for three reasons: ranges could overlap, ingredients in two ranges should only be counted once, and going through the whole ingredient range manually would take hours even on the best CPUs. I did eventally come up with a solution I liked:
  1. For each range, check if its end numbers are in any other range.
  2. If either end is, combine the two ranges in question by setting one range to the minimum minimum and the maximum maximum, and the other to 0-0 (which would be ignored later).
  3. If any range is combined, restart checks for the current range as to not accidentally miss a range that's now in reach.
  4. Once all ranges have been checked, none will overlap. Add up the sizes of all ranges +1, and return.
Day 6: Trash Compactor Part 1 was pretty simple - just loaded each number into memory, recorded how long the row was, and read * and + to check what operation to do
The main change for part 2 was reading digits instead of numbers, and not skipping spaces. Then, I could iterate through each column, read the */+ conveniently positioned at the start of the problem, and read numbers down from the column.
For detecting blank columns, I could take advantage of the fact that zero doesn't appear anywhere in the input; so if I read a column as zero, it was definitely blank.
Day 7: Laboratories This one ended up pretty simple; keep a target row and a source row of memory, read the line, apply the correct behaviour, and swap rows for the next line.
Part 2 also had a simple solution; instead of writing 1, write the number of rays the space currently represents. The count of lasers at the end can be adapted from the split count, just start with 1 and add the number of rays split when a splitter is hit.
Day 8: Playground Always remember to use the right bit width for the operation you need, kids. While writing the distance function needed for this challenge, I was using i32s. Unfortunately, numbers like 91073 exist that, when squared, overflow, resulting in mysteriously getting 910732=3999324033 instead of 8294291329. Even worse, adding together the values could overflow again. Safe to say, I was not getting anywhere near the right results until I converted to i64s before squaring.
Once that was out of the way, the rest was a matter of creating and merging groups 1000 times and summing up the number of nodes in each group at the end. For part 2, the loop just keeps connecting pairs until group 1 has all 1000 nodes in it.
Day 9: Movie Theater This one was fortunately very similar to the previous day in a lot of ways, such as the reading of sets of numbers and comparing every node to every other, so I was able to just strip down and tweak yesterday's code. Part 2 was significantly more challenging, and I had a couple ways I thought of to solve it: Clearly, C was the way to go. I also got to copy some more code over from Day 8 to keep track of what pairs I'd checked already and not check those again.
Despite being the most efficient route for checking if a selection is valid, it still needs to check a lot of possible selections (about 48000), meaning this will take about 15-30s to run. Expect the page to freeze.