day 9 completion (somehow)

This commit is contained in:
2019-11-18 07:25:23 -06:00
parent 90f5ccf6c8
commit dd12c5aa7d
4 changed files with 31 additions and 0 deletions

0
2018/day-10/input Normal file
View File

View File

View File

@@ -0,0 +1 @@
419 players; last marble is worth 72164 points

View File

@@ -0,0 +1,30 @@
import os
import sys
import re
from collections import deque, defaultdict
RE_PATTERN = "(\d+) players; last marble is worth (\d+) points"
PATH = os.path.join(sys.path[0], '..', 'input')
MATCH = re.match(RE_PATTERN, open(PATH, 'r').read())
PLAYERS = int(MATCH.group(1))
LAST_MARBLE = int(MATCH.group(2))
def game(players, last_marble):
circle = deque([0])
scores = defaultdict(int)
for marble in range(1, last_marble + 1):
if marble % 23 == 0:
circle.rotate(7)
scores[marble % players] += marble + circle.pop()
circle.rotate(-1)
else:
circle.rotate(-1)
circle.append(marble)
print(max(scores.values()))
game(PLAYERS, LAST_MARBLE)
game(PLAYERS, LAST_MARBLE * 100)