bjorng
Erlang Core Team
Note: This topic is to talk about Day 19 of the Advent of Code.
For general discussion about the Advent of Code 2018 and links to topics of the other days, see this topic.
Trending in Challenges
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
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
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
bjorng
Here is my solution for Day 19.
I did not even attempt to make a solution that would solve part 2 for any input (in a reasonable time).
Instead, I looked at the trace of the execution of my input and found the inner loop. I then wrote an optimized version of the inner loop.
To run the optimized version, I implemented a general mechanism for installing a breakpoint handler and installed my optimized inner loop as a breakpoint handler. The breakpoint handler will only be installed for code similar to my input program (it must be the same instructions, but it registers could be different).
My solution runs in less than 20 seconds.
sasajuric
This idea with installing the optimized loop is very interesting.
I just reverse engineered the entire program. I started by inspecting the first 100 states to quickly figure out where’s the inner loop, what is its input, and what is the effect of a single pass through it on the registers. Then I annotated my program and spent some time understanding what it does. After awhile, it became clear to me that the program first computes the input number, stores it to r4, and then iteratively finds all the divisors of that number, adding them into r0 (which is set to 0 before entering the loop). So finally, I wrote the equivalent program in Elixir
The complete solution is here, and it takes about 6 sec combined for both parts.
josevalim
I got stuck but after reading your replies I tried to also optimize the loop and I arrived to the same conclusion as @sasajuric: part 2 is basically computing the sum of all divisors for a given number, with some busy wait thrown in for good measure, haha.
However, I have optimized it slightly differently. If I trace the results I get this:
My instruction point is in the 2nd register and I noticed that when it has value 1, it is when the loop starts, so I just need to get the number at position 4th in the registry and compute the sum of its divisors. So I added this instruction:
Both parts finish in 0.6 seconds.
This is by far the puzzle that took me the longest.
stefanchrobot
I actually wrote a decompiler/debugger in Elixir to poke with the program. It was sooo much fun!
With the tool at hand, after a few initial steps in which the program initializes the register 5 with a big number, I could run “seti 10 0 5” while the program was running. After that it was quite easy to trace what the program is computing.