aoc2023/d09/run2.py

24 lines
430 B
Python
Raw Normal View History

2023-12-10 15:24:34 +00:00
import sys
L = sys.stdin.read().splitlines()
S = 0
for report in L:
l = [int(r) for r in report.split(' ')]
prem = [l[0]]
while not all(v == 0 for v in l):
m = []
for i in range(0,len(l)-1):
m.append(l[i+1] - l[i])
prem.append(m[0])
l = list(m)
s = prem[0]
signe = -1
for a in prem[1:]:
s+=(a*signe)
signe *= -1
S+=s
print(S)