MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_125/sol1.py:35–53  ·  view source on GitHub ↗

Returns the sum of all numbers less than 1e8 that are both palindromic and can be written as the sum of consecutive squares.

()

Source from the content-addressed store, hash-verified

33
34
35def solution() -> int:
36 """
37 Returns the sum of all numbers less than 1e8 that are both palindromic and
38 can be written as the sum of consecutive squares.
39 """
40 answer = set()
41 first_square = 1
42 sum_squares = 5
43 while sum_squares < LIMIT:
44 last_square = first_square + 1
45 while sum_squares < LIMIT:
46 if is_palindrome(sum_squares):
47 answer.add(sum_squares)
48 last_square += 1
49 sum_squares += last_square**2
50 first_square += 1
51 sum_squares = first_square**2 + (first_square + 1) ** 2
52
53 return sum(answer)
54
55
56if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 2

is_palindromeFunction · 0.70
addMethod · 0.45

Tested by

no test coverage detected