this time with no legal info
This commit is contained in:
34
2/Ex1-redo.py
Normal file
34
2/Ex1-redo.py
Normal file
@@ -0,0 +1,34 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user