liamcmitchell

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

My solution:

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

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

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

bjorng

Erlang Core Team

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.

https://github.com/bjorng/advent-of-code/blob/main/2024/day21/lib/day21.ex

Last Post!

ken-kost

ken-kost

Yep, working. :+1:

Where Next?

Popular in Challenges Top

bjorng
Note: This topic is to talk about Day 6 of the Advent of Code 2019. There is a private leaderboard for elixirforum members. You can join...
New
bjorng
Note: This topic is to talk about Day 18 of the Advent of Code 2019. There is a private leaderboard for elixirforum members. You can joi...
New
Aetherus
This topic is about Day 5 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/le...
New
bjorng
This topic is about Day 14 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/l...
New
bjorng
This topic is about Day 6 of the Advent of Code 2021. We have a private leaderboard (shared with users of Erlang Forums ): https://adve...
New
igorb
So… that’s it? Everyone is stuck on part 2? :slight_smile: I looked at Reddit hints and thought I probably wouldn’t have come up with the...
New
Aetherus
Today’s problem is really tense. I don’t think I can do it without libgraph.
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New

We're in Beta

About us Mission Statement