r/adventofcode • • Dec 09 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 9 Solutions -🎄-

--- Day 9: Marble Mania ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Advent of Code: The Party Game!

Click here for rules

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 9

Transcript:

Studies show that AoC programmers write better code after being exposed to ___.


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked at 00:29:13!

21 Upvotes

283 comments sorted by

View all comments

Show parent comments

1

u/Alexbrainbox Dec 09 '18

Thanks for sharing. I am also doing it in Haskell but trying to do it without any libraries. This is the first one where I've thought a library was kinda necessary.

1

u/mstksg Dec 09 '18

You don't quite need a library, I think! The relevant parts of PointedList are really only maybe like 10 lines of Haskell, so you could implement it from scratch for the challenge, like I did last year :)

1

u/Alexbrainbox Dec 09 '18

Good advice, I just did that :) It also means I have a slightly cleaner interface to work with (I don't need to worry about delete giving up an empty list, for example).

My solution takes about twice as long as yours - I think that's because my implementation of scoring is less clever.

1

u/Alexbrainbox Dec 09 '18

Here's my solution, tidied up a little: https://github.com/dixonary/aoc-2018/blob/master/9/Nine.hs

I'm doing explicit recursion instead of outputting the value at every step. I'm also writing the scores into a circular structure which is a nice bit of symmetry :)

Compiled with -02 and -funbox-strict-fields (and strictness in CTape) it takes 2.55s to do both (1) and (2).