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:

39276-eeb74f9a

1 Like

Here is my solution.

2 Likes

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.

2 Likes

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:

2 Likes

Here’s my solution.

6 Likes

No cheat this time:

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

3 Likes

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

3 Likes

(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: https://github.com/cblavier/advent/blob/0fe0010188de83aef15a007801fa51246861901a/lib/2019/day5/day5.ex

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.

edit:

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

2 Likes

Fighting day 5: https://www.youtube.com/watch?v=QaAmHcqwCKc

Source at: https://gist.github.com/ferd/a5c88c589df81d9e8754bac7e8457eba

2 Likes

Here’s mine: https://github.com/keathley/advent_of_code_2019/blob/master/lib/aoc/vm.ex. My original design was pretty easy to change to support the parameter modes and whatnot so that felt good.

1 Like