summaryrefslogtreecommitdiffstats
path: root/prog/aoc/23
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2023-12-09 13:14:43 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2023-12-09 13:14:43 +0100
commit05d5afb18e4bcf733f2c86e8b591adf8a907f9a0 (patch)
tree3310fa99b9227db0d28edef8be29f363576ad25c /prog/aoc/23
parentaoc8 (diff)
downloadr-05d5afb18e4bcf733f2c86e8b591adf8a907f9a0.tar
r-05d5afb18e4bcf733f2c86e8b591adf8a907f9a0.tar.gz
r-05d5afb18e4bcf733f2c86e8b591adf8a907f9a0.tar.bz2
r-05d5afb18e4bcf733f2c86e8b591adf8a907f9a0.tar.lz
r-05d5afb18e4bcf733f2c86e8b591adf8a907f9a0.tar.xz
r-05d5afb18e4bcf733f2c86e8b591adf8a907f9a0.tar.zst
r-05d5afb18e4bcf733f2c86e8b591adf8a907f9a0.zip
Diffstat (limited to 'prog/aoc/23')
-rwxr-xr-xprog/aoc/23/9/1.py32
-rw-r--r--prog/aoc/23/9/in.txt3
2 files changed, 35 insertions, 0 deletions
diff --git a/prog/aoc/23/9/1.py b/prog/aoc/23/9/1.py
new file mode 100755
index 0000000..3d16c5c
--- /dev/null
+++ b/prog/aoc/23/9/1.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python3
+data = []
+try:
+ while True:
+ data.append([[x for x in map(int, input().split(" "))]])
+except EOFError:
+ pass
+s = 0
+for d in data:
+ while len(set(d[-1])) != 1 or d[-1][0] != 0:
+ r = []
+ for idx in range(len(d[-1])-1):
+ r.append(d[-1][idx+1]-d[-1][idx])
+ d.append(r)
+ for idx in range(len(d)):
+ if idx == 0:
+ d[-1].append(0)
+ continue
+ idx = -idx-1
+ d[idx].append(d[idx][-1]+d[idx+1][-1])
+ s += d[0][-1]
+print(s)
+s2 = 0
+for d in data:
+ for idx in range(len(d)):
+ if idx == 0:
+ d[-1].insert(0, 0)
+ continue
+ idx = -idx-1
+ d[idx].insert(0, d[idx][0]-d[idx+1][0])
+ s2 += d[0][0]
+print(s2)
diff --git a/prog/aoc/23/9/in.txt b/prog/aoc/23/9/in.txt
new file mode 100644
index 0000000..539a763
--- /dev/null
+++ b/prog/aoc/23/9/in.txt
@@ -0,0 +1,3 @@
+0 3 6 9 12 15
+1 3 6 10 15 21
+10 13 16 21 30 45