project-euler/125_palindromic_sums.py

20 lines
332 B
Python

#!/usr/bin/env python3
from math import sqrt
def is_palindrome(n):
return str(n) == str(n)[::-1]
lim = 10**8
nums = []
for n in range(2, int(sqrt(lim))+1):
s = (n-1)**2 + n**2
while s < lim:
if is_palindrome(s) and s not in nums:
nums.append(s)
n += 1
s += n**2
print(sum(nums))