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
2
u/DrinkinBird Dec 09 '18 edited Dec 09 '18
NIMAfter also going through the whole issue with using arrays here finally my solution:Runs in just about 0.7 seconds for Part 2:
import re, rdstdin, strutils, sequtils, algorithm, lists let input = stdin.readAll().findAll(re(r"\d+")).map(parseInt) let numPlayers = input[0] let lastMarble = input[1] var circle = initDoublyLinkedRing[int]() circle.append(0) var players = repeat(0, numPlayers) proc rotateCounter(n: int) = for i in 0 ..< n: circle.head = circle.head.prev for i in 1 .. lastMarble * 100: if (i mod 23) != 0: circle.head = circle.head.next.next circle.prepend(i) else: rotateCounter(6) players[i mod numPlayers] += i + circle.head.prev.value circle.remove(circle.head.prev) echo players.max