d09 part two

This commit is contained in:
Arthur 2023-12-10 16:24:34 +01:00
parent 9815821fb7
commit 2495c41ba3
1 changed files with 26 additions and 0 deletions

26
d09/run2.py Normal file
View File

@ -0,0 +1,26 @@
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)