It would be great to do this, but acknowledge that every day solving the solutions is probably enough. Anyhow, I’m already behind some time to catchup!!
I’ve been getting rusty trying to split my time between Elixir in my free time and Node.js for client work, so I figure now is a perfect time to brush up on Elixir.
I love doing challenges like this and looking at other peoples solutions. I’ve started Advent of Code the past two years but I’ve never finished. I’m determined this year. I started reading Seven Languages in Seven Weeks and plan on attempting them in some of the more obscure languages (namely prolog and io).
Here are my solutions for Day1 and Day2 in elixir, I’m hoping to knock out Day3 tonight as soon as I figure out a pattern in the spiral.
I just solved day 5 and I am quite unhappy with the runtime of my version. Especially the second assignment of today takes a long time. 10 to 15 seconds.
The code can be found in my repo: (but of course it spoils if you haven’t finished yet)
Day 5, second assignment, my slow solution
I'm currently thinking about implementing it with some kind of zypper, but if this would really provide any benefits, I'm unsure...
I get similar times (~ 15 sec), and I also use map to store instructions. I briefly tried with ETS, which shaved a few secs. One thing which I thought of, but didn’t try was to optimize the case where the current instruction is 0. In that case, you can skip extra map store/lookup and immediately move on to the next iteration (though you need to somehow indicate that you made two moves). I didn’t really have the time to try it out, and it would uglify the code, so I just left it as it was.
Here’s my day 5 solution. I originally kept it simple using list lookups and replacements, and later made it a little faster by reducing the initial list into a map.
I spent some time (way too much time) trying to come up with a divide and conquer or backtracing algorithm to make things more efficient, but the changing offsets seemed to make this impossible. Sub-solutions can’t be guaranteed to be isolated. I’d love to see if someone found an efficient solution.