21 lines
387 B
Python
21 lines
387 B
Python
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)
|