JEG2

JEG2

Author of Designing Elixir Systems with OTP

Note: This topic is to talk about Day 9 of the Advent of Code.

For general discussion about the Advent of Code 2018 and links to topics of the other days, see this topic.

Showing Posts 1 to 6

JEG2

JEG2 OP

Author of Designing Elixir Systems with OTP

Here’s my solution to Day 9:

https://github.com/JEG2/advent_of_code_2018/blob/master/day_09/marble_mania.exs

Inspired by @josevalim, I live streamed the creation of it for the first time. You can watch the video here (until it falls off Twitch 14 days from now):

The main idea is just that I hand-rolled a doubly linked list and used that to solve both problems. It does part two in a little under a minute. I’m looking forward to seeing how others do it faster.

sasajuric

sasajuric

Author of Elixir In Action

This is my solution to day 9. On my machine it takes some 3.5 sec for the second part. The key idea in my solution is to use zippers to implement a circular list.

davydog187

davydog187

Here’s my naive solution use a single list. The implementation was too slow to solve the second part. advent_of_code_2018/advent_elixir/lib/advent_elixir/day_9.ex at master · davydog187/advent_of_code_2018 · GitHub

sfusato

sfusato

I liked your implementation of a linked-list as a Map structure. Also, the way you’ve found the 7th marble counter clockwise from the current one using Stream.iterate was awesome. I need to get acquainted with the Stream module more that’s for sure. I’ve enjoyed your stream. Thank you!

My very naive implementation wouldn’t complete Part 2 within the time I was willing to wait for it to do so. I got Part 1 and the given tests passing, so I’m cool with that.

poligen

poligen

Thank you so much to reply here !!@sasajuric. It is the most important key to solve this problem using your zipper list. I learn a lot from this zippers.
:heart_eyes:

simon

simon

My solution is here and it calculates the part 2 solution in about 30 seconds.

I need to now look at what others have done but I think I was on roughly the right track by creating a map where the key is the turn number and the value is a struct containing the previous and next keys so that you can step forwards and backwards from the current marble.

My code to update the struct isn’t terribly concise and that may be a good place for performance improvements but @sasajuric’s solution seems to be the one I need to look at in depth as well as the aforementioned zippers.

— All posts loaded —

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
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews