Day 2: Part 1

This commit is contained in:
2025-12-02 09:33:38 +01:00
parent f25ccf9b15
commit bf06795b6b
3 changed files with 160 additions and 0 deletions

20
day2/main.py Normal file
View File

@@ -0,0 +1,20 @@
def is_invalid_id(n: int) -> bool:
s = str(n)
if len(s) % 2 != 0:
return False
half = len(s) // 2
return s[:half] == s[half:]
total = 0
with open("input.txt") as f:
line = f.read().strip()
for part in line.split(","):
lo, hi = map(int, part.split("-"))
for n in range(lo, hi + 1):
if is_invalid_id(n):
total += n
print(total)