A
Advent Of Code 2025
9 days ago
sohilgoud@gmail.com
...
Day 2 - Puzzle 1
# line = "11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124"
line = "7777742220-7777814718,3201990-3447830,49-86,653243-683065,91-129,24-41,1-15,2678-4638,1407-2511,221-504,867867-942148,1167452509-1167622686,9957459726-9957683116,379068-535983,757-1242,955118-1088945,297342-362801,548256-566461,4926-10075,736811-799457,1093342-1130060,620410-651225,65610339-65732429,992946118-993033511,5848473-5907215,17190619-17315301,203488-286290,15631-36109,5858509282-5858695889,87824047-87984031,1313113913-1313147594,795745221-795825571,46303-100636,4743038-4844422"
total_sum = 0
def find_even_low_high_values(low, high):
low_digits = len(str(low)) #994 -> 3 digits
if low_digits % 2 != 0:
new_low = 1
for i in range(low_digits):
new_low *= 10
low = str(new_low)
high_digits = len(str(high)) #12994 -> 5 digits
if high_digits % 2 != 0:
new_high = 1
for i in range(high_digits):
new_high *= 10
new_high = int (new_high / 10) - 1
high = str(new_high)
return [low, high]
def find_invalid_nums(low, high):
local_list = []
low_size = len(low) // 2
low_a, low_b = int(low[:low_size]), int(low[low_size:])
high_size = len(low) // 2
high_a, high_b = int(high[:high_size]), int(high[high_size:])
while low_a < high_a:
num = int(str(low_a) * 2)
if int (low) <= num <= int (high):
local_list.append(num)
low_a = low_a + 1
if high_b >= low_a >= low_b:
local_list.append(int(str(low_a) * 2))
return local_list
num_list = []
for i in line.split(","):
[low, high] = i.split("-")
print(f"{"="*20}")
print(f"low: {low}, high: {high}")
[low, high] = find_even_low_high_values(low, high)
print(f"new_low: {low}, new_high: {high}")
if int (low) > int (high):
print(f"No invalid values here")
print("")
continue
local_list = find_invalid_nums(low, high)
print(f"local_list: {local_list}")
print("")
num_list.extend(local_list)
print(num_list)
sum = 0
for num in num_list:
sum += num
print(sum)
2
Join Conversation
vishalchiluveri@gmail.com
9 days ago
...
There is a bug in your code please check
0
Advent Of Code 2025
Advent Of Code 2025
Dec 21, 2025
Public
1
Members
1
Moderators
...
I can’t answer your question. You need to do fix it on your own