igorb
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
Trending in Challenges
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
adamu
Yep. I did part 1 just to prove to myself that part 2 was going to be “and now a bazillion secrets??”, but was pleasantly surprised.
My part 2 takes ~7 seconds on a Core i5.
For each secret, I built a map of changes to bananas, using
Map.put_new/3to make sure I didn’t count a repeated sequence. Then I merged all the maps together, and took the maximum.https://git.adamu.jp/adam/AdventOfCode/src/branch/main/2024/day22.exs
lud
Brute force going for 3.2 seconds on part 2:
I wonder what optimizations could be made other than memoizing.
lud
@adamu I can see we had the same approach. When I saw I could just merge the sequences I was happy haha.
adamu
Alright, you made me crack out the M4. 2.67 seconds. Now we’re even
I also realised I used
Enum.sum_by/2, which was just added in Elixir 1.18I can’t believe I didn’t do that and serialized to string instead. Fixing that gets it down to 7.5s on the i5.
rvnash
Anyone care to help me out on part 2? I took a straight forward brute force approach and my answer is off by 50? The code works on the small example. I’ve been going over it carefully for an hour now, and I can’t find the bug.
I copied in @igorb 's code, because he was first here, and his works (of course). We both come up with the same best sequence, but his total bananas on my input data is is 1831 while mine is 1881.
https://github.com/rvnash/aoc2024/blob/main/lib/d22.ex
Thanks if you take a look.
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
lud
Maybe this ?
If I read correctly you are not yet finding the best price, so you should not keep the best price here. The puzzle says that you need to keep the first price for each different sequence.
Also instead of:
You can write:
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.
rvnash
That was it. Thanks so much! I didn’t fully get the instructions. Now I can go on with my day.
lud
I found a first optimization on reddit.
Instead of doing:
It is possible to do:
That’s not a game changer but it definitely improve times.