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!

22 Upvotes

283 comments sorted by

View all comments

Show parent comment

2

u/dorfsmay Dec 11 '18

Possibly, also collections.deque doesn't have a remove an operation to remove a piece in the middle, interestingly enough the suggested solution to do so in the doc is rotate, pop, and rotate back!

If you don't index your linked list, you should be able to do an insert or remove op in O(1), no? I believe that's what I'm doing with my full object implementation. Now that I know that rotating a deque is the way to go, I might spend more time on my object solution, find what's the bottleneck and see if it can be implemented to run at a reasonable speed (it's currently 5 times slower than with a list).

1

u/narcindin Dec 12 '18

I think the key technique left unsaid here is that u/marcusandrews keeps the currently mable at the front of the deque. So he never had to remove from the middle.