Files
AdventOfCode/2023/day09/solutions/python1.py
T
2023-12-11 16:45:35 -06:00

19 lines
409 B
Python

with open("../example.txt", "r") as fp:
inputs = fp.read().strip().split("\n")
for i, inp in enumerate(inputs):
inputs[i] = list(map(int,inputs[i].split()))
sum = 0
for seq in inputs:
rows = []
while len(seq) > 0 and set(seq) != {0}:
rows.append(seq)
tmp = seq
seq = []
for i in range(len(tmp) - 1):
seq.append(tmp[i + 1] - tmp[i])
for r in rows:
sum += r[-1]
print(sum)