diff --git a/2018/day-10/input b/2018/day-10/input new file mode 100644 index 0000000..e69de29 diff --git a/2018/day-10/python/main.py b/2018/day-10/python/main.py new file mode 100644 index 0000000..e69de29 diff --git a/2018/day-9/input b/2018/day-9/input index e69de29..0458ff4 100644 --- a/2018/day-9/input +++ b/2018/day-9/input @@ -0,0 +1 @@ +419 players; last marble is worth 72164 points \ No newline at end of file diff --git a/2018/day-9/python/main.py b/2018/day-9/python/main.py index e69de29..95237fa 100644 --- a/2018/day-9/python/main.py +++ b/2018/day-9/python/main.py @@ -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) \ No newline at end of file