d09 part two
This commit is contained in:
parent
9815821fb7
commit
2495c41ba3
|
@ -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)
|
Loading…
Reference in New Issue