27 lines
533 B
Python
27 lines
533 B
Python
def is_invalid_part2(n: int) -> bool:
|
|
s = str(n)
|
|
L = len(s)
|
|
for k in range(1, L // 2 + 1):
|
|
if L % k != 0:
|
|
continue
|
|
block = s[:k]
|
|
if block[0] == "0":
|
|
continue
|
|
if block * (L // k) == s:
|
|
return True
|
|
return False
|
|
|
|
|
|
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_part2(n):
|
|
total += n
|
|
|
|
print(total)
|