aboutsummaryrefslogtreecommitdiff
path: root/2025/03/b.py
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-12-03 06:22:35 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-12-03 06:22:35 +0100
commit39e9d936f52c7626884d1ca4c5262b117b0dc85c (patch)
tree02bd60816e10f0f9253d89d10755388c03eaa01c /2025/03/b.py
parentd662d817052767047807f8f1d5643608b9943fa0 (diff)
downloadaoc-39e9d936f52c7626884d1ca4c5262b117b0dc85c.tar.gz
aoc-39e9d936f52c7626884d1ca4c5262b117b0dc85c.zip
Day 3 2025
Diffstat (limited to '2025/03/b.py')
-rw-r--r--2025/03/b.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/2025/03/b.py b/2025/03/b.py
new file mode 100644
index 0000000..4c74ae6
--- /dev/null
+++ b/2025/03/b.py
@@ -0,0 +1,18 @@
1import fileinput
2from functools import cache
3
4neginf = -1e13
5
6@cache
7def joltage(line, n):
8 if n == 0:
9 return 0
10 if n > len(line)-1:
11 return neginf
12 j = 0
13 for i in range(len(line)-1):
14 j = max(j, int(line[i])*10**(n-1)+joltage(line[i+1:],n-1))
15 return j
16
17with fileinput.input() as lines:
18 print(sum(joltage(line, 12) for line in lines))

Generated with cgit - Back to sebastiano.tronto.net