project-euler/125_palindromic_sums.py

20 lines
332 B
Python
Raw Normal View History

2023-03-26 17:21:44 +02:00
#!/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))