project euler problem 4 https projecteuler netproblem4 largest palindrome product a palindromic number reads the same both ways the largest palindrome made from the product of two 2digit numbers is 9009 91 99 find the largest palindrome made from the product of two 3digit numbers references https en wikipedia orgwikipalindromicnumber returns the largest palindrome made from the product of two 3digit numbers which is less than n solution20000 19591 solution30000 29992 solution40000 39893 solution10000 traceback most recent call last valueerror that number is larger than our acceptable range fetches the next number checks whether strnumber is a palindrome if number is a product of two 3digit numbers then number is the answer otherwise fetch next number returns the largest palindrome made from the product of two 3 digit numbers which is less than n solution 20000 19591 solution 30000 29992 solution 40000 39893 solution 10000 traceback most recent call last valueerror that number is larger than our acceptable range fetches the next number checks whether str_number is a palindrome if number is a product of two 3 digit numbers then number is the answer otherwise fetch next number
def solution(n: int = 998001) -> int:
    

    
    for number in range(n - 1, 9999, -1):
        str_number = str(number)

        
        if str_number == str_number[::-1]:
            divisor = 999

            
            
            while divisor != 99:
                if (number % divisor == 0) and (len(str(number // divisor)) == 3.0):
                    return number
                divisor -= 1
    raise ValueError("That number is larger than our acceptable range.")


if __name__ == "__main__":
    print(f"{solution() = }")