problem 125 https projecteuler netproblem125 the palindromic number 595 is interesting because it can be written as the sum of consecutive squares 62 72 82 92 102 112 122 there are exactly eleven palindromes below onethousand that can be written as consecutive square sums and the sum of these palindromes is 4164 note that 1 02 12 has not been included as this problem is concerned with the squares of positive integers find the sum of all the numbers less than 108 that are both palindromic and can be written as the sum of consecutive squares check if an integer is palindromic ispalindrome12521 true ispalindrome12522 false ispalindrome12210 false returns the sum of all numbers less than 1e8 that are both palindromic and can be written as the sum of consecutive squares check if an integer is palindromic is_palindrome 12521 true is_palindrome 12522 false is_palindrome 12210 false returns the sum of all numbers less than 1e8 that are both palindromic and can be written as the sum of consecutive squares
LIMIT = 10**8


def is_palindrome(n: int) -> bool:
    
    if n % 10 == 0:
        return False
    s = str(n)
    return s == s[::-1]


def solution() -> int:
    
    answer = set()
    first_square = 1
    sum_squares = 5
    while sum_squares < LIMIT:
        last_square = first_square + 1
        while sum_squares < LIMIT:
            if is_palindrome(sum_squares):
                answer.add(sum_squares)
            last_square += 1
            sum_squares += last_square**2
        first_square += 1
        sum_squares = first_square**2 + (first_square + 1) ** 2

    return sum(answer)


if __name__ == "__main__":
    print(solution())