aoc2023/d09/run.py

13 lines
307 B
Python
Raw Permalink Normal View History

2023-12-09 12:50:09 +00:00
import sys
L = [list(map(int,l.split(' '))) for l in sys.stdin.read().splitlines()]
def extrapolate(L):
if all(a == 0 for a in L):
return 0
M = [b-a for a,b in zip(L,L[1:])]
return L[-1]+extrapolate(M)
print(sum(extrapolate(l) for l in L))
print(sum(extrapolate(l[::-1]) for l in L))