Skip to content

Commit 153fb31

Browse files
committed
Day 5
1 parent 82c7272 commit 153fb31

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

aoc/2025/05/05.vn.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Advent of code Day 05
2+
# https://adventofcode.com/2025/day/5
3+
# 05/12/2025
4+
5+
from collections import defaultdict
6+
from tqdm.auto import tqdm
7+
8+
with open("input.txt") as file:
9+
inp = list(map(str.strip, file.readlines()))
10+
11+
res1, res2 = 0, 0
12+
13+
stop = inp.index("")
14+
ranges = list(
15+
map(
16+
lambda x: tuple(map(int, x.split("-"))),
17+
inp[:stop]
18+
)
19+
)
20+
21+
ingredients = list(
22+
map(
23+
int,
24+
inp[stop + 1:]
25+
)
26+
)
27+
28+
for ingredient in ingredients:
29+
for l, r in ranges:
30+
if l <= ingredient and ingredient <= r:
31+
res1 += 1
32+
break
33+
34+
ranges = sorted(ranges)
35+
for i in range(len(ranges) -1):
36+
l, r = ranges[i]
37+
l1, r1 = ranges[i + 1]
38+
if r >= l1:
39+
ranges[i + 1] = (l, max(r, r1))
40+
ranges[i] = (0, -1)
41+
42+
for l, r in ranges:
43+
res2 += r - l + 1
44+
45+
print(res1, res2)

aoc/2025/05/animated/05_animated.vn.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

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

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)