Skip to content

Instantly share code, notes, and snippets.

@mrklein
Created September 26, 2012 23:19
Show Gist options
  • Save mrklein/3791235 to your computer and use it in GitHub Desktop.
Save mrklein/3791235 to your computer and use it in GitHub Desktop.
Euler #125
#!/usr/bin/env python
from math import sqrt, floor
N = 100000000
def is_palindrome(n):
return str(n) == str(n)[::-1]
def sum_list(n):
res = set()
for i in xrange(n - 1, 0, -1):
l = [x*x for x in xrange(i, n + 1)]
t = sum(l)
if t > N:
break
if is_palindrome(t):
res.add(t)
return list(res)
if __name__ == '__main__':
t = int(sqrt(N/2)) + 1
l = [item for sublist in map(sum_list, xrange(2, t + 1)) for item in sublist]
print len(set(l)), sum(set(l))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment