From 980acef7625b66d85cd5a6f64f7188c5df508556 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Sat, 9 Dec 2023 19:41:13 +0100 Subject: [PATCH] Finished on 2023-12-09 p2 --- 2023/day9/part2.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/2023/day9/part2.py b/2023/day9/part2.py index 5b679d1..a98c3c4 100644 --- a/2023/day9/part2.py +++ b/2023/day9/part2.py @@ -13,38 +13,30 @@ t = [] def calc(line): global t t.append(line) - print(line) diff = [] for i in range(0,len(line)-1): diff.append(line[i+1]-line[i]) if not all(v == 0 for v in diff): last.append(diff[-1]) calc(diff) - else: - print(diff) return 0 -prev = 0 - result = [] +left = [] for mdx,m in enumerate(maps): t = [] - left = [] last = [] last.append(m[-1]) last.append(calc(m)) result.append(reduce(lambda x, y: x+y, last)) - print(t) -pprint(last) -print(sum(result)) -pprint(t) + + tx = [] + tmp = 0 + for i in range(len(t)-1,-1,-1): + tx.append(t[i][0]) + tmp = t[i][0] - tmp + left.append(tmp) -tx = [] +print('Part 1: ' + str(sum(result))) +print('Part 2: ' + str(sum(left))) -tmp = 0 -for i in range(len(t)-1,-1,-1): - tx.append(t[i][0]) - tmp = t[i][0] - tmp - -print(tx) -print(tmp)