[2025 Day 2 (Part 1)] [Python] What could be the cause of low result?
I'm new to python and this is my first AOC, so if there are any libraries that I should check out/resources, please let me know. My answer is too low. I know that my attempt isn't the most efficient, but I cannot figure out what to do. I'm not sure if it's because my solution is so slow, maybe there's an issue with how I check the numbers. Please give me hints and tips.
#find dash index
dash = 0
def find_ranges(range_list):
dash = range_list.index('-')
# use dash to get starting num and ending num
start = range_list[:dash]
end = range_list[dash+1:]
return start, end
def compare_strings(start,end):
count = 0
for k in range(int(start), int(end)+1):
#print(k)
#turn into string
number_string = str(k)
#if string length is odd go to next number
if len(number_string) %2 != 0:
#print(f'{stg}not even')
continue
#split in half
length = len(number_string) // 2
#print(length)
#compare halves
#print(f'number is: {stg} first half:{stg[:length]} second half: {stg[length:]}')
if number_string[:length] == number_string[length:]:
count += 1
#print(f'number is: {number_string} first half:{number_string[:length]} second half: {number_string[length:]}')
#print(f'{number_string[:length]} equals {number_string[length:]}')
return count
res = 0
for i in range(0, len(ranges)):
range_pair = find_ranges(ranges[i])
print(range_pair)
res += compare_strings(range_pair[0],range_pair[1])
print(res)
Posted Dec 3, 2025, 1:54 AM UTC
26