DEV Community

Discussion on: AoC Day 1: Chronal Calibration

Collapse
alephnaught2tog profile image
Max Cerrina • Edited on

First version, with Elixir, was ~15 seconds, to do what ended up being 130+ iterations on part two.

After some careful matching down to a more or less more-than-binary tree, I got it to about 10 seconds.

... then I went nuts and decided to see if I could do it with JUST sending messages aaaaaaand boy does Elixir do well with that, because I got it to 1.5 seconds total.

I just doublechecked and it is still hitting that loop the same number of times. 137991.

Collapse
jpyamamoto profile image
Juan Pablo Yamamoto

Did it with Elixir too. I found the Stream module to be quite useful, especially for the first part. For the second part, I'm not sure my approach is best, but at least it is working.
If you want to check my repo: github.com/JPYamamoto/advent_of_co...

Collapse
alephnaught2tog profile image
Max Cerrina

Yeah, that's what I started with and definitely what I would like actually use for anything. It's soooooooo much more readable like how you have it! The trick with named Processes I did totally works here but I suspect would become insanely complex or fail as soon as you needed data that relied on the other data too, instead of just "has this been seen before" :D

Thread Thread
jpyamamoto profile image
Juan Pablo Yamamoto

Also, I suspect there's a way to do the second part with Streams and avoid having so much information in memory as I did with my approach. Maybe something that takes advantage of Stream.cycle and Stream.scan. But not sure how to implement it. I'll let you know if I figure it out. 😀

Thread Thread
alephnaught2tog profile image
Max Cerrina

Yeah, I kept my memory footprint relatively low I think even in version one because I read everything into the IO stream and then just kept throwing that list around, which wasn't greaaaaaaaaaaaat but.

Collapse
alephnaught2tog profile image
Max Cerrina
Collapse
rpalo profile image
Ryan Palo Author

Wow, nice!

Collapse
alephnaught2tog profile image
Max Cerrina

Thanks! I rechecked it like five times because I was so surprised.