aboutsummaryrefslogtreecommitdiff
path: root/2025/02/b.py
diff options
context:
space:
mode:
Diffstat (limited to '2025/02/b.py')
-rw-r--r--2025/02/b.py25
1 files changed, 25 insertions, 0 deletions
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

Generated with cgit - Back to sebastiano.tronto.net