aoc2023/d09/part2.py

12 lines
275 B
Python
Raw Normal View History

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