-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13.py
56 lines (39 loc) · 761 Bytes
/
13.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
from lib import *
input = read_input(2017, 13)
lines = input.splitlines()
R = {}
S = {}
for line in lines:
a, b = map(int, line.split(": "))
R[a] = b
S[a] = 0
n = max(S)
out = 0
for i in range(n):
if i in S and S[i] == 0:
out += i * R[i]
for k, v in S.items():
S[k] = (v + 1) % (R[k] * 2 - 2)
print(out)
def step(R, S):
for k, v in S.items():
S[k] = (v + 1) % (R[k] * 2 - 2)
R = {}
SC = {}
for line in lines:
a, b = map(int, line.split(": "))
R[a] = b
SC[a] = 0
n = max(SC)
def test():
S = SC.copy()
for i in range(n + 1):
if i in S and S[i] == 0:
return False
step(R, S)
return True
k = 0
while not test():
k += 1
step(R, SC)
print(k)