summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-12-09 20:48:48 +0100
committerlonkaars <loek@pipeframe.xyz>2023-12-09 20:48:48 +0100
commitb81cc71523fdfe9065e34e09c24c78fe3fbdce98 (patch)
tree627d58e53ba8bfeed0fa3f68df001bb1a259f62d
parent36bbb27ab186687a3a9b7b07e5ee6a4a13521ca9 (diff)
day 9 part 1
-rwxr-xr-x09/main.py26
1 files changed, 26 insertions, 0 deletions
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}")
+