[Python/2017] Move solutions into .py files
This commit is contained in:
parent
fbc5fda60f
commit
7b1efc0d9c
51 changed files with 1100 additions and 4546 deletions
56
Python/2017/13.py
Normal file
56
Python/2017/13.py
Normal file
|
@ -0,0 +1,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)
|
Loading…
Add table
Add a link
Reference in a new issue