liamcmitchell
Advent of Code 2024 - Day 21
A frustrating one for me. I spent a long time trying to understand why some combinations resulted in fewer presses and struggled to keep track of all the layers.
A few things that helped:
- shortest sequences will always use repeated keys e.g.
V<<, never<V< - if a sequence starts and ends on
A, it is independent, cacheable and there is no need to keep track of the keys once summed
Part 1 example (2.1ms): 126384
Part 1 input (0.9ms): 157908
Part 2 example (14.2ms): 154115708116294
Part 2 input (10.8ms): 196910339808654
I passed a cache map every but don’t like it. Is there a nicer way to cache without external deps or using Process? I’ll have a look into macros.
Most Liked
lud
I’m pulling my hair so hard. I can’t reason about this… I spend so many time on that. I just found the correct answer for part 1.
The concept is very fun but it’s also kind of tedious…
Edit: well part 2 is not a surprise hahaha
rvnash
I worked on this for hours and got pretty much no where. I knew exactly what I wanted to do, but I could not clear my head enough to do it. Gave up.
bjorng
This took quite a while to figure out and implement correctly, and to make fast enough to handle part 2.
The resulting code is surprisingly fast: the combined runtime for both parts is 0.01 seconds.
adamu
Lol I came here for the answer and you’re all like “too hard
”…
FWIW spent a couple of hours on it, but my code got a length 4 too long for the 4th sample. It’s the first time I failed on the sample in part 1. I suspected it was something to do with the < arrow key being further away, but following my rule of not letting AoC take over my life, I gave up ![]()
bjorng
I don’t know how your Input module is implemented, so I couldn’t run your code without modifications.
If run my code with your input, it doesn’t crash.
If I take your code and replace your parse function with my parse function, it produces the correct result for my input.
So I suspect that something is wrong with either your parse function or your Input module.
With your input, my parse function returns the following:
[{803, "803A"}, {528, "528A"}, {586, "586A"}, {341, "341A"}, {319, "319A"}]







