5
votes
Day 21: Keypad Conundrum
Today's problem description: https://adventofcode.com/2024/day/21
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>
Well, it took me a good while, but I finally got this working. Correctly generating the most efficient paths between buttons was one of the sticking points for me - the priorities of each direction were difficult to wrap my head around. Part 2 wasn't too bad once I realized there was no feasible way to work with the strings directly, luckily. A good majority of my time was spent on part 1. I'm not especially happy with my final solution (I think it's quite messy and could have been structured much better), but I do not want to work on this puzzle any further.
Solution (Jai)
Definitely a step up in difficulty from the previous few days! I was shocked to almost make the leaderboard for part 1, but definitely struggled a bit more with part 2. I spent some time after refactoring to generalize the keypads a bit, though I still wouldn't describe today's solution as particularly comprehensible.
Solution Logic
The core insight was that, while each level was different, the best move sequence to get from one key to another was always the same for a given level. With 5 keys to move between and 25 levels, this leads to a manageable number of options to test.
Pharo Smalltalk Solution
This puzzle broke my brain, and not in a good way. :(
After spending over 10 hours on it and only solving part 1, I gave up and looked up the solution. This is especially galling -- I really wanted to solve one AoC on my own, without needing help, which didn't work out last year either. So I guess I can try again next year. Really not feeling motivated to complete the calendar at all, tbh.
And of course the solution turned out to be relatively simple again and should have been solveable with the tools I had at my disposal if I just had had a small bit of insight that was missing
Spoiler
-- that you can use pairs of characters instead of going character-by-character or A-button-by-A-button.
Solution, I guess