mirror of
https://github.com/Xevion/advent-of-code.git
synced 2025-12-06 03:14:20 -06:00
day 9 completion (somehow)
This commit is contained in:
0
2018/day-10/input
Normal file
0
2018/day-10/input
Normal file
0
2018/day-10/python/main.py
Normal file
0
2018/day-10/python/main.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
419 players; last marble is worth 72164 points
|
||||||
@@ -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)
|
||||||
Reference in New Issue
Block a user