We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 34c562b commit 4b2b5c1Copy full SHA for 4b2b5c1
2025/day02/solution.py
@@ -0,0 +1,33 @@
1
+with open("input") as f:
2
+ inp = f.read().strip().split(",")
3
+
4
5
+def split_string(s, n):
6
+ return [s[i:i+n] for i in range(0, len(s), n)]
7
8
9
+def is_invalid(s, part1 = True):
10
+ if len(s) == 1:
11
+ return False
12
+ if part1:
13
+ if len(s) % 2 == 1:
14
15
+ if len(set(split_string(s, len(s)//2))) == 1:
16
+ return True
17
+ else:
18
+ for i in range(1, len(s)):
19
+ if len(set(split_string(s, i))) == 1:
20
21
22
23
24
+ans_pt1, ans_pt2 = 0, 0
25
+for s in inp:
26
+ l, r = s.split("-")
27
+ for x in range(int(l), int(r) + 1):
28
+ if is_invalid(str(x), part1 = True):
29
+ ans_pt1 += x
30
+ if is_invalid(str(x), part1 = False):
31
+ ans_pt2 += x
32
33
+print(ans_pt1, ans_pt2)
0 commit comments