We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4b2b5c1 commit 5abadd0Copy full SHA for 5abadd0
1 file changed
2025/day03/solution.py
@@ -0,0 +1,34 @@
1
+with open("input") as f:
2
+ inp = f.read().strip().split("\n")
3
+
4
5
+def find_largest_int(s):
6
+ m = max(int(i) for i in s)
7
+ m = str(m)
8
+ return m, s.index(m)
9
10
11
+def joltage(s):
12
+ x1, i1 = find_largest_int(s[:-1])
13
+ x2, _ = find_largest_int(s[(i1+1):])
14
+ return int(x1 + x2)
15
16
17
+# Part 1
18
+print(sum(joltage(s) for s in inp))
19
20
21
+# Part 2
22
+def joltage2(s):
23
+ res = ""
24
+ i = -1
25
+ for n in range(12):
26
+ start = i + n + 1
27
+ end = n - 11 if n < 11 else None
28
+ x, di = find_largest_int(s[start:end])
29
+ i += di
30
+ res += x
31
+ return int(res)
32
33
34
+print(sum(joltage2(s) for s in inp))
0 commit comments