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 776492d commit 887cec2Copy full SHA for 887cec2
2025/day05/solutions.py
@@ -0,0 +1,25 @@
1
+with open("input") as f:
2
+ ls = f.read().splitlines()
3
+
4
+ranges = []
5
+ingrs = []
6
+for l in ls:
7
+ if "-" in l:
8
+ a, b = l.split("-")
9
+ ranges.append([int(a), int(b)])
10
+ elif l:
11
+ ingrs.append(int(l))
12
13
+# Part 1
14
+print(sum(any(start <= i <= end for start, end in ranges) for i in ingrs))
15
16
+# Part 2
17
+# Merge ranges
18
+ranges.sort()
19
+merged = []
20
+for start, end in ranges:
21
+ if not merged or merged[-1][1] < start - 1:
22
+ merged.append([start, end])
23
+ else:
24
+ merged[-1][1] = max(merged[-1][1], end)
25
+print(sum(end - start + 1 for start, end in merged))
0 commit comments