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

Here is my solution.

I cheated again :stuck_out_tongue_winking_eye:

Very ugly code:

https://github.com/Aetherus/advent_of_code/blob/master/2019/day05.rb

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.

https://github.com/sb8244/advent-of-code-2019/blob/master/lib/5.ex

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:

https://github.com/Aetherus/advent_of_code/blob/master/2019/day05.exs

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)

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:

https://gitlab.com/NobbZ/aoc_ex/blob/19-5/lib/y2019/d5.ex

Also the VM might be interesting;

https://gitlab.com/NobbZ/aoc_ex/blob/19-5/lib/y2019/intcode_vm.ex

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: advent/lib/2019/day5/day5.ex at 0fe0010188de83aef15a007801fa51246861901a · cblavier/advent · GitHub

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

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: https://www.youtube.com/watch?v=QaAmHcqwCKc

Source at: day05.erl · GitHub

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