Advent of Code 2019 - Day 5

Note: This topic is to talk about Day 5 of the Advent of Code 2019.

There is a private leaderboard for elixirforum members. You can join it by following this link and entering the following code:


1 Like

Here is my solution.


I cheated again :stuck_out_tongue_winking_eye:

Very ugly code:

1 Like

This one tripped me up quite a bit! I originally separated the “registers” from the program itself, on day 2, but code is data and I had to make them the same map.


Here is my day 5, it’s not pretty.

I got stuck debugging “assembly” for quite some time because the last test case was returning nil instead of 999 for < 8.

Eventually, I gave up debugging and submitted anyway and it worked. :man_shrugging:


Here’s my solution.


No cheat this time:

I wonder is there a way to call private functions dynamically.


Making heavy use of higher-order functions. I even have functions to modify higher order functions. Worked the first time, somehow.


(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

1 Like

But what if I wanna call private functions with different arities? I guess I need to unify them.

Very intriguing. I’m gonna try that too.

Use Kernel.apply/2.

Okay, I got the first part up and running successfully.

After factoring the VM from day 2 into its own module, refactoring it a bit, doing bugfixing and then enhencing it, the solution itself for day 5a was pretty straight forward.

I do not have the time anymore to continue on part 2 (haven’t even read it so far) as I have to do some office work. It might become evening until I have the possibility to do side coding again. Therefore I link to the current solution in the work in progress branch:

Also the VM might be interesting;

PS: The VM is totally unoptimized! The day2 runtimes suffer significantly, though optimizing the VM is not something I could find the time for in the couple of days/weeks…

Pfeww, I had a hard time to find out bugs in my code, but I finally did it …

Here is my solution :slight_smile:

I finished part 2 now. Links on master are as follows (purposefully not as a onebox)

I really have to rework how I handle arities and pass the access-modes around, that feels bottlenecky (though measuring might proof me wrong, as always)

Still optimising it, is not yet scheduled.


Today I considered extracting and enhencing the VM from day 2 the real challenge, not the solving of the actual problem, and I’m really looking forward to follow ups that extend the VM even further!

This is also the reason why I will probably do them on a separate branch, as then the refactoring/enhencing process is easier to follow comapred to have some huge commit on master.

Fifth day in a row writing elixir, definitely having a good time.

My solution

1 Like

My solution

Here’s my Day5 solution
and some tests to capture the output with capture_io/1

I wanted to read the user input from :stdin with IO.gets/1 but the result is a bit messy because to test the most of the functions I had to pass a function that mocks IO.gets/1, returning a value…

@sasajuric nice the queues as user input, really neat! I think I’m going to refactor mine


Fighting day 5:

Source at:


Here’s mine: My original design was pretty easy to change to support the parameter modes and whatnot so that felt good.

1 Like