Files
advent-of-code/2025/05/main.py

63 lines
1.5 KiB
Python

#!/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}")