30 lines
725 B
Python
30 lines
725 B
Python
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))
|