From 23d9e8f9bf4a1aef01745ac120472a94fb46ca0d Mon Sep 17 00:00:00 2001 From: kwout Date: Sat, 9 Dec 2023 09:44:17 -0500 Subject: [PATCH] 2023 day 9 part 1 solved --- 2023/9.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 2023/9.py diff --git a/2023/9.py b/2023/9.py new file mode 100644 index 0000000..0328d0f --- /dev/null +++ b/2023/9.py @@ -0,0 +1,11 @@ +input = [[int(i) for i in l.split()] for l in open("input.txt", 'r').read().splitlines()] +score = 0 + + +def diff(l): + newList = [l[i+1] - l[i] for i in range(len(l)-1)] + return l[-1] + diff(newList) if set(newList) != {0} else l[-1] + +score = sum(diff(l) for l in input) + +print(score) \ No newline at end of file