(update) day 5 part 1+2

This commit is contained in:
2025-12-21 11:31:26 +01:00
parent 899002a7a5
commit cf756f0482
3 changed files with 1261 additions and 0 deletions

11
2025/05/example Normal file
View File

@ -0,0 +1,11 @@
3-5
10-14
16-20
12-18
1
5
8
11
17
32

1188
2025/05/input Normal file

File diff suppressed because it is too large Load Diff

62
2025/05/main.py Normal file
View File

@ -0,0 +1,62 @@
#!/bin/env python
FRESH_LIST: list = []
def findInList(l: tuple, ingredient: str) -> int:
fresh = 0
low = l[0] if l[0] < l[1] else l[1]
high = l[0] if l[0] > l[1] else l[1]
if (
int(ingredient) >= low
and int(ingredient) <= high
and not ingredient in FRESH_LIST
):
FRESH_LIST.append(ingredient)
fresh = 1
return fresh
def countFreshIds(ingredient_range: tuple) -> None:
print("duh!")
def check_if_fresh(line: str) -> int:
return 0 if int(line.strip()) in FRESH_LIST else 1
with open("input", "+r") as file:
fresh_ingredients = 0
f = file.readlines()
lists = [
(
int(x.strip().split("-")[0]),
int(x.strip().split("-")[1]),
)
for x in f
if x.find("-") > 0
]
ingredients = [x.strip() for x in f if x.strip().isdigit()]
lists.sort() # .split("\n")[0]
# 01
for i, ingredient in enumerate(ingredients):
for l in lists:
fresh_ingredients += findInList(l, ingredient)
print(f"# fresh ingredients: {fresh_ingredients}")
# 02
FRESH_RANGES: list = []
total = 0
for start, end in lists:
if not FRESH_RANGES or start > FRESH_RANGES[-1][1] + 1:
FRESH_RANGES.append([start, end])
else:
FRESH_RANGES[-1][1] = max(FRESH_RANGES[-1][1], end)
for start, end in FRESH_RANGES:
total += end - start + 1 # range(start, end).__len__()
print(f"# range: {total}")