Add day 9

This commit is contained in:
Sijmen 2018-12-09 14:36:34 +01:00
parent 26306cdefb
commit 74657f9c73
1 changed files with 30 additions and 0 deletions

30
Day9/Day9.py Normal file
View File

@ -0,0 +1,30 @@
from sys import argv, exit
from blist import blist
try:
PLAYER_COUNT = int(argv[1])
LAST_MARBLE = int(argv[2])
except (IndexError, ValueError):
print(f"Usage: {argv[0]} [player_count] [marble_count]")
exit(1)
marbles = blist([0, 2, 1])
current_id = 1
scores = [0] * PLAYER_COUNT
player = 2
for next_marble in range(3, LAST_MARBLE + 1):
if next_marble % 23 == 0:
current_id = (current_id - 7) % len(marbles)
scores[player] += next_marble + marbles.pop(current_id)
else:
current_id += 2
if current_id > len(marbles):
current_id %= len(marbles)
marbles.insert(current_id, next_marble)
player = (player + 1) % PLAYER_COUNT
print(max(scores))