Day 2: Part 1
This commit is contained in:
20
day2/main.py
Normal file
20
day2/main.py
Normal 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)
|
||||
Reference in New Issue
Block a user