Skip to content

Commit 4b2b5c1

Browse files
committed
Add day02, 2025
1 parent 34c562b commit 4b2b5c1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

2025/day02/solution.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
return False
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+
return True
21+
return False
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

Comments
 (0)