From 1d4c5f6f81f3cf8635bc622f0558016f3208443d Mon Sep 17 00:00:00 2001 From: setop Date: Sat, 9 Dec 2023 09:17:26 +0100 Subject: [PATCH] day 9, trivial recursion --- d09/part1.py | 11 +++++++++++ d09/part2.py | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 d09/part1.py create mode 100644 d09/part2.py diff --git a/d09/part1.py b/d09/part1.py new file mode 100644 index 0000000..358e22c --- /dev/null +++ b/d09/part1.py @@ -0,0 +1,11 @@ +import sys + +L = [list(map(int,l.split(' '))) for l in sys.stdin.read().splitlines()] + +def extrapolate(L): + if all(not a for a in L): + return L+[0] + M = [b-a for a,b in zip(L,L[1:])] + return L+[L[-1]+extrapolate(M)[-1]] + +print(sum(extrapolate(l)[-1] for l in L)) diff --git a/d09/part2.py b/d09/part2.py new file mode 100644 index 0000000..ad8aa8b --- /dev/null +++ b/d09/part2.py @@ -0,0 +1,11 @@ +import sys + +L = [list(map(int,l.split(' '))) for l in sys.stdin.read().splitlines()] + +def extrapolate(L): + if all(not a for a in L): + return [0]+L + M = [b-a for a,b in zip(L,L[1:])] + return [L[0]-extrapolate(M)[0]]+L + +print(sum(extrapolate(l)[0] for l in L))