Skip to content

Commit 93a1306

Browse files
committed
Day 3
1 parent a2568c4 commit 93a1306

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

aoc/2025/03/normal/03_normal.vn.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
# Advent of code Day 03
22
# https://adventofcode.com/2025/day/3
33
# 03/12/2025
4-
4+
5+
from tqdm.auto import tqdm
6+
from functools import cache
7+
8+
with open("input.txt", "r") as f:
9+
inp = f.readlines()
10+
11+
res1, res2 = 0, 0
12+
13+
@cache
14+
def best(row, n, start=0):
15+
if len(row) - start < n or n == 0: return 0
16+
17+
return max(
18+
best(row, n, start + 1), row[0] * 10**(n-1) + best(row[1:], start + 1, n - 1)
19+
)
20+
21+
for row in tqdm(inp):
22+
row = tuple(map(int, row.strip()))
23+
res1 += best(row, 2)
24+
res2 += best(row, 12)
25+
26+
27+
28+
print(res1, res2)
29+

0 commit comments

Comments
 (0)