34 lines
960 B
Python
34 lines
960 B
Python
ranQ = []
|
|
|
|
count = 0
|
|
|
|
with open("input.txt") as file:
|
|
input = file.read().strip()
|
|
|
|
ranges = input.split(",")
|
|
|
|
for ran in ranges:
|
|
start, end = ran.split("-")
|
|
if len(start) == len(end):
|
|
if len(start) % 2 == 0:
|
|
ranQ.append((int(start), int(end)))
|
|
else:
|
|
if len(start) % 2 == 0:
|
|
ranQ.append((int(start), 10**len(start)- 1))
|
|
elif len(end) % 2 == 0:
|
|
ranQ.append((10**len(start), int(end)))
|
|
|
|
|
|
for start, end in ranQ:
|
|
done = []
|
|
print(f"Processing range: {start} to {end}")
|
|
start_prefix = str(start)[:len(str(start))//2]
|
|
end_prefix = str(end)[:len(str(end))//2]
|
|
for prefix in range(int(start_prefix), int(end_prefix) + 1):
|
|
candidate = int(str(prefix) * 2)
|
|
if start <= candidate <= end and candidate not in done:
|
|
print(f"Adding: {candidate}")
|
|
count += int(candidate)
|
|
done.append(candidate)
|
|
|
|
print(count) |