27 lines
941 B
Python
27 lines
941 B
Python
#!/bin/env python3
|
|
|
|
with open("input", "+r") as file:
|
|
line = file.readline()
|
|
ranges = line.split(",")
|
|
invalid = 0
|
|
INVALID_NUMBERS = []
|
|
for values in ranges:
|
|
low = int(values.split("-")[0])
|
|
high = int(values.split("-")[1])
|
|
for i in range(low, high + 1):
|
|
to_string = str(i)
|
|
split_max = int(to_string.__len__() / 2)
|
|
for split_at in range(1, split_max + 1):
|
|
if i in INVALID_NUMBERS:
|
|
continue
|
|
left = to_string[:split_at]
|
|
has_to_have: float = to_string.__len__() / split_at
|
|
if not has_to_have.is_integer():
|
|
continue
|
|
if to_string.count(left) == has_to_have:
|
|
INVALID_NUMBERS.append(i)
|
|
invalid = invalid + i
|
|
print(f"{i} is invalid.")
|
|
print(INVALID_NUMBERS)
|
|
print("result", invalid)
|