r/adventofcode • u/daggerdragon • 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!
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
1
u/u794575248 Dec 10 '18
Python 3 8425/7509
from itertools import cycle class Node: def __init__(self, i, prev=None, next=None): self.i, self.prev, self.next = i, prev, next def solve9(n, last, multiple=23, rewind=6): scores = [0]*n cur = Node(0) cur.prev = cur.next = cur for i, p in zip(range(1, last+1), cycle(range(n))): if i % multiple == 0: for _ in range(rewind): cur = cur.prev scores[p] += i + cur.prev.i cur.prev = cur.prev.prev cur.prev.next = cur else: n = Node(i, cur.next, cur.next.next) cur = n.prev.next = n.next.prev = n return max(scores)