OFFSET
1,1
LINKS
Project Euler, Problem 125: Palindromic Sums.
EXAMPLE
a(8) = 7 is because 7 consecutive squares are needed to sum to A216446(8) = 595 = 6^2 + 7^2 + 8^2 + 9^2 + 10^2 + 11^2 + 12^2.
PROG
(Python)
is_palindrome = lambda n: str(n) == str(n)[::-1]
def g(L):
L2, squares, D = L*L, [x*x for x in range(0, L + 1)], {}
for i in range(1, L + 1):
for j in range(i + 1, L + 1):
candidate = sum(squares[i:j+1])
if candidate < L2 and is_palindrome(candidate):
if candidate in D:
D[candidate]= min(D[candidate], j-i-1)
else:
D[candidate] = j-i+1
return [D[k] for k in sorted(D.keys())]
print(g(1000))
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Darío Clavijo, Jul 10 2023
STATUS
approved