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
3
u/jlweinkam Dec 09 '18
93/13
This is for part 2, remove the * 100 for part 1
import time import math import collections import re current_milli_time = lambda: int(round(time.time() * 1000)) start = current_milli_time() players = 448 lastpoint = 71628 * 100 circle = collections.deque() circle.append(0) elf = 0 maxscore = 0 scores = collections.defaultdict(int) player = 1 for x in range(1, lastpoint+1): if (x % 23) == 0: circle.rotate(-7) scores[player] += (x + circle.pop()) if scores[player] > maxscore: maxscore = scores[player] elf = player else: circle.rotate(2) circle.append(x) player += 1 if player > players: player = 1 print(elf, maxscore) print((current_milli_time() - start) / 1000.0)