diff options
Diffstat (limited to '09')
-rwxr-xr-x | 09/main.py | 26 |
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}") + |