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

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews