commit 39e9d936f52c7626884d1ca4c5262b117b0dc85c
parent d662d817052767047807f8f1d5643608b9943fa0
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Wed, 3 Dec 2025 06:22:35 +0100
Day 3 2025
Diffstat:
3 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/2025/03/a.py b/2025/03/a.py
@@ -1,6 +1,18 @@
import fileinput
+s = 0
with fileinput.input() as lines:
for line in lines:
- ...
-
+ m1 = 0
+ m2 = 0
+ mi = -1
+ for i in range(len(line)-2):
+ if int(line[i]) > m1:
+ m1 = int(line[i])
+ mi = i
+ for i in range(mi+1, len(line)-1):
+ if int(line[i]) > m2:
+ m2 = int(line[i])
+ print(10*m1+m2)
+ s += 10*m1+m2
+print(s)
diff --git a/2025/03/b.py b/2025/03/b.py
@@ -0,0 +1,18 @@
+import fileinput
+from functools import cache
+
+neginf = -1e13
+
+@cache
+def joltage(line, n):
+ if n == 0:
+ return 0
+ if n > len(line)-1:
+ return neginf
+ j = 0
+ for i in range(len(line)-1):
+ j = max(j, int(line[i])*10**(n-1)+joltage(line[i+1:],n-1))
+ return j
+
+with fileinput.input() as lines:
+ print(sum(joltage(line, 12) for line in lines))
diff --git a/README.md b/README.md
@@ -14,4 +14,4 @@ See `year/README.md` for instructions on how to run my code.
|2022| 50 | Rust | Done in 2025 to learn Rust |
|2023| 50 | C | All solved by December 25, 2023 |
|2024| 50 | C++ | Each solved within 24h |
-|2025| 4 | Python | Work in progress... |
+|2025| 6 | Python | Work in progress... |