4
votes
Day 15: Warehouse Woes
Today's problem description: https://adventofcode.com/2024/day/15
Please post your solutions in your own top-level comment. Here's a template you can copy-paste into your comment to format it nicely, with the code collapsed by default inside an expandable section with syntax highlighting (you can replace python
with any of the "short names" listed in this page of supported languages):
<details>
<summary>Part 1</summary>
```python
Your code here.
```
</details>
I agree with everyone else here. This was a bit tricky to implement, but I understood what I was supposed to be doing almost instantly. I did get tripped up on edge cases a bit for part 2, though, and I think my final solution is one of the worst I've written this year so far - it's overly long and hard to parse. Luckily, it seems to be more than performant enough.
Solution (Jai)
My original solution for part 1 did not use recursion, and, in my opinion, was much nicer than what I ended up with. I'll include it here; it's a replacement for the
get_gps_sum()
procedure.Part 1-only solution
There isn't anything particularly interesting to say about this one, since it was essentially just an exercise in translating the mechanics of the puzzle into code, and didn't require any clever tricks or optimizations. It took me about 40 minutes of fiddling around to get the cascading pushing to work correctly in part 2.
Part 1 (Python)
Part 2 (Python)
Gonna agree with @Hello that this wasn't particularly interesting from a how-do-i-do-this perspective, but I felt like it was a nice programming exercise -- after all Advent of Code is supposed to make you a better programmer.
That said, it also took me about 40 minutes to fiddle with part 2, and my code ended up kind of ugly and, as usual, verbose. I'm always amazed what you guys can accomplish with code that is so much shorter and, often, simpler.
Edit: After a refactoring pass, it's not quite as bad anymore.
Part 2 (Rust)
Definitely my longest day as far as LOC, but that's mostly because there's lots of repeated code for the slightly different cases. Paired with the way Pharo outputs to text files it's nearing 200 lines...
Other than getting tripped up again with input parsing (I've updated my tools to avoid it going forward), this was a pretty smooth day.
Pharo Smalltalk Solution