igorb
Advent of Code 2024 - Day 22
Today was a nice break from Day 21. Part 2 is just brute-force, with a bit of optimization tracking what sequences return how many bananas per number: advent-of-code-2024/lib/advent_of_code2024/day22.ex at main · ibarakaiev/advent-of-code-2024 · GitHub
Most Liked
lud
I found a first optimization on reddit.
Instead of doing:
seq = {a,b,c,d} # last 4 price changes
Map.put(sequences, seq, price)
It is possible to do:
<<seq::integer-20>> = <<a::5, b::5, c::5, d::5>>
Map.put_new(sequences, seq, price)
That’s not a game changer but it definitely improve times.
bjorng
This was a nice break after the last two days.
The combined runtime for both parts is 2.4 seconds.
https://github.com/bjorng/advent-of-code/blob/main/2024/day22/lib/day22.ex
adamu
(lud beat me to it while typing)
It says that the bid is placed as soon as the sequence occurs. So even if there’s a better price for a later secret (same seed, later iteration) with the same sequence, that’s too late and shouldn’t be used.
Popular in Challenges
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








