## Project Euler 125: Finding square sums that are palindromic

#### Problem Description

The palindromic number 595 is interesting because it can be written as the sum of consecutive squares: 6^{2} + 7^{2} + 8^{2} + 9^{2} + 10^{2} + 11^{2} + 12^{2}.

There are exactly eleven palindromes below one-thousand that can be written as consecutive square sums, and the sum of these palindromes is 4164. Note that 1 = 0^{2} + 1^{2} has not been included as this problem is concerned with the squares of positive integers.

Find the sum of all the numbers less than 10^{8} that are both palindromic and can be written as the sum of consecutive squares.

#### Analysis

Build sequences of consecutive squares and record those that are palindromic. Once the sum has exceeded our limit, L, we can break from the current sequence starting number and start with the next. We use a set to eliminate duplicate sum-of-squares.

#### Project Euler 125 Solution

Runs < 0.350 seconds in Python 2.7.```
from Euler import is_palindromic
L = 10**8
sqrt_limit = int(L ** 0.5)
pal = set()
for i in range(1, sqrt_limit-1):
sos = i*i
for j in xrange(i+1, sqrt_limit):
sos += j*j
if sos >= L: break
if is_palindromic(sos): pal.add(sos)
print "Answer to PE125 =", sum(pal), len(pal)
```

Use this link to get the Project Euler 125 Solution Python 2.7 source.#### Answer

Slowly swipe from either end beginning with the white vertical bar to get an idea of the starting or ending digits. For less drama, just double click the answer area. The distance between the two bars will give you an idea of the magnitude. Touch devices can tap and hold the center of the box between the two bars and choose define to reveal the answer.#### Comments

- Function
`is_palindromic`

is listed in Common Functions and Routines for Project Euler - Takes 381,232 iterations.
- The second number printed is the size of the set.

*Project Euler 125 Solution last updated*

## Discussion

## No comments yet.