blob: f0aa4bf2cbc30195326ce27c40e4f27ade9676f0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
import sys
sys.path.append("../common")
import aoc
from collections import deque
words = aoc.data.split(" ")
playercount = int(words[0])
lastworth = int(words[6])
def highscore(playercount, lastworth):
lastworth = lastworth - lastworth % 23
players = [0 for x in range(playercount)]
marbles = deque([0])
pos = 0
for i in range(1, lastworth+1):
if i % 23 == 0:
cp = (i-1) % playercount
players[cp] += i + marbles[(len(marbles) + pos - 7) % len(marbles)]
marbles.rotate((len(marbles) - 1 - pos) + 7)
marbles.pop()
pos = 0
else:
if i < 3:
pos = 1
marbles.rotate(1)
marbles.append(i)
else:
marbles.rotate((len(marbles)- 1 -pos) - 1)
marbles.append(i)
pos = len(marbles)-1
return max(players)
def solve1(args):
return highscore(playercount, lastworth)
def solve2(args):
return highscore(playercount, lastworth * 100)
aoc.run(solve1, solve2, sols=[412127, 3482394794])
|