Day 5 - Advent of Code 2025
5 December 2025
Working solutions for the day 5 puzzles.
Part One
""" day_05_01.py """
# usage: python3 day_05_01.py < input
import sys
with sys.stdin as infile:
fresh = []
while line := infile.readline().strip():
fresh.append(list(map(int, line.split('-'))))
fresh.sort()
total = 0
while line := infile.readline().strip():
for begin, end in fresh:
if begin <= int(line) <= end:
total += 1
break
print(total)Part Two
""" day_05_02.py """
# usage: python3 day_05_02.py < input
import sys
with sys.stdin as infile:
ids = []
while line := infile.readline().strip():
ids.append(list(map(int, line.split('-'))))
ids.sort()
while True:
for i, _ in enumerate(ids[:-1]):
[x1, y1], [x2, y2] = ids[i], ids[i + 1]
if x2 > y1:
continue
ids = ids[:i] + [[x1, max(y1, y2)]] + ids[i + 2:]
break
else:
break
total = sum(y - x + 1 for x, y in ids)
print(total)