aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2025/02/a.py13
-rw-r--r--2025/02/b.py25
-rw-r--r--README.md2
3 files changed, 38 insertions, 2 deletions
diff --git a/2025/02/a.py b/2025/02/a.py
index 5fdb11b..9c6fd84 100644
--- a/2025/02/a.py
+++ b/2025/02/a.py
@@ -1,6 +1,17 @@
1import fileinput 1import fileinput
2 2
3def invalid(n):
4 return n[:len(n)//2] == n[len(n)//2:]
5
6s = 0
3with fileinput.input() as lines: 7with fileinput.input() as lines:
4 for line in lines: 8 for line in lines:
5 ... 9 for r in line.split(","):
10 l = r.split("-");
11 for n in range(int(l[0]), int(l[1])+1):
12 if invalid(str(n)):
13 print(n)
14 s += n
15print(s)
16
6 17
diff --git a/2025/02/b.py b/2025/02/b.py
new file mode 100644
index 0000000..8efdbe3
--- /dev/null
+++ b/2025/02/b.py
@@ -0,0 +1,25 @@
1import fileinput
2
3def invk(n, k):
4 for i in range(0, len(n)-k, k):
5 if n[i:i+k] != n[i+k:i+2*k]:
6 return False
7 return True
8
9def invalid(n):
10 for k in range(1, len(n)//2 + 1):
11 if invk(n, k):
12 return True
13 return False
14
15s = 0
16with fileinput.input() as lines:
17 for line in lines:
18 for r in line.split(","):
19 l = r.split("-");
20 for n in range(int(l[0]), int(l[1])+1):
21 if invalid(str(n)):
22 s += n
23print(s)
24
25
diff --git a/README.md b/README.md
index 6bfd776..4a41f60 100644
--- a/README.md
+++ b/README.md
@@ -14,4 +14,4 @@ See `year/README.md` for instructions on how to run my code.
14|2022| 50 | Rust | Done in 2025 to learn Rust | 14|2022| 50 | Rust | Done in 2025 to learn Rust |
15|2023| 50 | C | All solved by December 25, 2023 | 15|2023| 50 | C | All solved by December 25, 2023 |
16|2024| 50 | C++ | Each solved within 24h | 16|2024| 50 | C++ | Each solved within 24h |
17|2025| 2 | Python | Work in progress... | 17|2025| 4 | Python | Work in progress... |

Generated with cgit - Back to sebastiano.tronto.net