bjorng

bjorng

Erlang Core Team

Note: This topic is to talk about Day 9 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

Showing Posts 1 to 10

bjorng

bjorng OP

Erlang Core Team

Here is my solution.

sb8244

sb8244

Author of Real-Time Phoenix

Nothing too exciting in my code here. My intcode computer has overall been a bit of a mess due to not going back and cleaning it up.

This problem really showed some issues in how I had implicit rules baked into my code. I was not putting arg 3 through any type of mode checking, because it was always itself previously. That bit me hard today, and I had to spend a ton of time debugging why my stuff wasn’t working.

mason-bially

mason-bially

I got top 80-90! Here is the meat of my solution.

I specifically designed my intcode interpreter to allow rapid extension of it, I even spent an hour cleaning it up the other day, seems like that paid off.

It’s pretty cool to see how well a recursive interpreter of a self-modifying memory/code VM actually ends up working with immutable memory. Very fun.

I would also be curious about the timings people got on the second part. Mine was 3.860 seconds (timed from the shell).

sb8244

sb8244

Author of Real-Time Phoenix

Wow!!! Great work. That’s super speedy.

I’m honestly surprised here. I feel like I didn’t do anything special to make mine fast, but it is significantly faster than 3s.

➜  advent_2019 git:(master) mix test test/solutions/9_test.exs
...

Finished in 0.6 seconds
3 tests, 0 failures

Do you use lists in your solution?

edit: I see that you use :array. I believe that switching over to an index based map would speed yours up significantly. I’ve learned to very rarely use [] or :array, from last year’s AoC.

mason-bially

mason-bially

To be clear I have used elixir less than a week and know nearly nothing about optimizing it (or erlang), I use advents of code to learn new languages.

I was worried a list would be too slow because of the O(n) access and couldn’t find good information on optimization. I figured the erlang :array would probably be better than that.

Could you point me to the documentation for what you are describing?

Edit: Is it simply just using integers in a map?

bjorng

bjorng OP

Erlang Core Team

Both parts finish in 0.1 seconds:

$ mix test
...

Finished in 0.1 seconds
3 tests, 0 failures
mason-bially

mason-bially

Looking at your code I feel like an idiot for missing that I can use the function pattern matching as a sort of multi-method. I may need to do some additional refactoring.

I’ll still have to always write a forwarding method, but it might make it a cleaner copy paste in the end rather than doing what I am now with the explicit forwarding.

sb8244

sb8244

Author of Real-Time Phoenix

Hm, I’m wrong here. I tried to do a benchmark with :array.get and :array.set vs Map functions and they were about the same. I’m not sure why it would be so much slower without digging in more.

mason-bially

mason-bially

I suspect my use of .exs and dynamically loading my libraries with Code.require_file("../day07/el.ex", __DIR__) might have something to do with it.

I haven’t learned mix yet…

Anyway thanks for the feed back! It was very useful.

Edit: some other possible reasons:

  • Pattern matches (wide ones too) in my main loop?
  • Probably not the right way of pattern/matching forwarding?

I’ll have to play around with it.

sasajuric

sasajuric

Author of Elixir In Action

This is my solution. So far I strived to keep the code clean, and this payed off, b/c the changes to the machine code were minimal. I finally extracted Intcode interpreter into a separate module, but I still keep that module code in the same file as the solution, so others can easily read the entire solution from a single file. As for the perf, the 2nd part takes about 500ms on my machine.

Where Next? Top

Trending in Challenges Top

Other Trending Topics Top

GenericJam
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
budgie
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
KristerV
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
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews