From b81cc71523fdfe9065e34e09c24c78fe3fbdce98 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 9 Dec 2023 20:48:48 +0100 Subject: day 9 part 1 --- 09/main.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 09/main.py diff --git a/09/main.py b/09/main.py new file mode 100755 index 0000000..7fb235f --- /dev/null +++ b/09/main.py @@ -0,0 +1,26 @@ +#!/bin/python3 +import sys + +def derivative(numbers): + output = [] + for x in range(len(numbers) - 1): + output.append(numbers[x+1] - numbers[x]) + return output + +output = 0 +for line in sys.stdin: + line = line.strip() + + numbers = [int(x) for x in line.split()] + derivatives = [numbers] + while len([x for x in derivatives[-1] if x != 0]) > 0: + derivatives.append(derivative(derivatives[-1])) + + prediction = 0 + for d in derivatives: + prediction += d[-1] + + output += prediction + +print(f">> {output}") + -- cgit v1.2.3