Returns the sum of all numbers less than 1e8 that are both palindromic and can be written as the sum of consecutive squares.
()
| 33 | |
| 34 | |
| 35 | def 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 | |
| 56 | if __name__ == "__main__": |
no test coverage detected