2025(02): solve part 1
This commit is contained in:
20
2025/02/part1.py
Normal file
20
2025/02/part1.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
with open("input", "r") as fp:
|
||||||
|
rangestrs = fp.read().split(",")
|
||||||
|
ranges = []
|
||||||
|
for rangestr in rangestrs:
|
||||||
|
a, b = rangestr.split("-")
|
||||||
|
a_int, b_int = int(a), int(b)
|
||||||
|
ranges.append((a, b))
|
||||||
|
assert a_int < b_int, f"Range invalid: {a} is not smaller than {b}"
|
||||||
|
|
||||||
|
illegal_counter = 0
|
||||||
|
illegal_sum = 0
|
||||||
|
for a, b in ranges:
|
||||||
|
a_int, b_int = int(a), int(b)
|
||||||
|
for num in range(a_int, b_int + 1):
|
||||||
|
num_str = str(num)
|
||||||
|
if len(num_str) % 2 == 0 and num_str[len(num_str) // 2:] == num_str[:len(num_str) // 2]:
|
||||||
|
illegal_counter += 1
|
||||||
|
illegal_sum += num
|
||||||
|
|
||||||
|
print(illegal_counter, illegal_sum)
|
||||||
1
2025/02/testinput
Normal file
1
2025/02/testinput
Normal file
@ -0,0 +1 @@
|
|||||||
|
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124
|
||||||
Reference in New Issue
Block a user