From 95665139a70d8c642b6979fa814c1ed9dc4ebb27 Mon Sep 17 00:00:00 2001 From: setop Date: Sat, 9 Dec 2023 13:50:09 +0100 Subject: [PATCH] day 9, refactor --- d09/part1.py | 11 ----------- d09/part2.py | 11 ----------- d09/run.py | 12 ++++++++++++ 3 files changed, 12 insertions(+), 22 deletions(-) delete mode 100644 d09/part1.py delete mode 100644 d09/part2.py create mode 100644 d09/run.py diff --git a/d09/part1.py b/d09/part1.py deleted file mode 100644 index 358e22c..0000000 --- a/d09/part1.py +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index ad8aa8b..0000000 --- a/d09/part2.py +++ /dev/null @@ -1,11 +0,0 @@ -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)) diff --git a/d09/run.py b/d09/run.py new file mode 100644 index 0000000..4914723 --- /dev/null +++ b/d09/run.py @@ -0,0 +1,12 @@ +import sys + +L = [list(map(int,l.split(' '))) for l in sys.stdin.read().splitlines()] + +def extrapolate(L): + if all(a == 0 for a in L): + return 0 + M = [b-a for a,b in zip(L,L[1:])] + return L[-1]+extrapolate(M) + +print(sum(extrapolate(l) for l in L)) +print(sum(extrapolate(l[::-1]) for l in L))