[2025 Day 5 (Part 1)] [Python] Am I misunderstanding the puzzle or my own code?

Help/Question

The instructions seems pretty straight forward to me. And yet my current solution is giving me an answer that is too low. Am I misunderstanding the instructions? Or is there a logical error in my code here:

with open("sample") as f:
    fresh, shelf = f.read().split("\n\n")
    shelf = {int(num) for num in shelf.splitlines()}
    fresh = {int(l): int(r) for l, r in [
        line.split("-") for line in fresh.splitlines()
    ]}

total = 0
for item in shelf:
    for l, r in fresh.items():
        if l <= item <= r:
            total += 1
            break

print(total)

Posted Dec 5, 2025, 8:04 AM UTC

39

Comments aren't archived yet

This post had 9 comments on Reddit. Comments for this period haven't been loaded into the archive yet.