commit c0c0f809bb5b2327db96c7dbb5e9ef8ea5960b00
parent 8e716a225ece98cf75cc1789c8f90757c0beadfc
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Tue, 2 Dec 2025 06:15:47 +0100
Day 2 2025 (solved part 2 before part 1 because I misread lol)
Diffstat:
3 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/2025/02/a.py b/2025/02/a.py
@@ -1,6 +1,17 @@
import fileinput
+def invalid(n):
+ return n[:len(n)//2] == n[len(n)//2:]
+
+s = 0
with fileinput.input() as lines:
for line in lines:
- ...
+ for r in line.split(","):
+ l = r.split("-");
+ for n in range(int(l[0]), int(l[1])+1):
+ if invalid(str(n)):
+ print(n)
+ s += n
+print(s)
+
diff --git a/2025/02/b.py b/2025/02/b.py
@@ -0,0 +1,25 @@
+import fileinput
+
+def invk(n, k):
+ for i in range(0, len(n)-k, k):
+ if n[i:i+k] != n[i+k:i+2*k]:
+ return False
+ return True
+
+def invalid(n):
+ for k in range(1, len(n)//2 + 1):
+ if invk(n, k):
+ return True
+ return False
+
+s = 0
+with fileinput.input() as lines:
+ for line in lines:
+ for r in line.split(","):
+ l = r.split("-");
+ for n in range(int(l[0]), int(l[1])+1):
+ if invalid(str(n)):
+ s += n
+print(s)
+
+
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| 2 | Python | Work in progress... |
+|2025| 4 | Python | Work in progress... |