From 7bc4e3f0667b04ad451fc44c3dda2f5b1a5d9164 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sat, 9 Dec 2023 12:00:12 +0000 Subject: much simpler --- 9.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/9.py b/9.py index a98d67a..9edf082 100644 --- a/9.py +++ b/9.py @@ -10,13 +10,7 @@ def predict_next(history: list[int]) -> int: ) -def predict_prev(history: list[int]) -> int: - if all(e == 0 for e in history): - return 0 - return history[0] - predict_prev([a - b for a, b in zip(history[1:], history[:-1])]) - - histories = [[int(e) for e in l.rstrip().split()] for l in stdin] print(sum(predict_next(history) for history in histories)) -print(sum(predict_prev(history) for history in histories)) +print(sum(predict_next(history[::-1]) for history in histories)) -- cgit v1.2.3-54-g00ecf