From 710b64d2ee78974dd6cba4f302edc3486cba0dba Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 10 Dec 2023 15:40:25 +0100 Subject: [PATCH] d09 part one --- d09/exemple1.txt | 3 +++ d09/run1.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 d09/exemple1.txt create mode 100644 d09/run1.py diff --git a/d09/exemple1.txt b/d09/exemple1.txt new file mode 100644 index 0000000..70c5595 --- /dev/null +++ b/d09/exemple1.txt @@ -0,0 +1,3 @@ +0 3 6 9 12 15 +1 3 6 10 15 21 +10 13 16 21 30 45 \ No newline at end of file diff --git a/d09/run1.py b/d09/run1.py new file mode 100644 index 0000000..9f7195f --- /dev/null +++ b/d09/run1.py @@ -0,0 +1,20 @@ +import sys + +L = sys.stdin.read().splitlines() +S = 0 +for report in L: + l = [int(r) for r in report.split(' ')] + m = list(l) + latest=[] + latest.append(m[-1]) + + while not all(v == 0 for v in l): + m = [] + for i in range(0,len(l)-1): + m.append(l[i+1] - l[i]) + + latest.append(m[-1]) + l = list(m) + S+=sum(latest) + +print(S) \ No newline at end of file