Return the sum of all numbers, less than n , which are palindromic in base 10 and base 2. >>> solution(1000000) 872187 >>> solution(500000) 286602 >>> solution(100000) 286602 >>> solution(1000) 1772 >>> solution(100) 157 >>> solution(10) 25 >>
(n: int = 1000000)
| 37 | |
| 38 | |
| 39 | def solution(n: int = 1000000): |
| 40 | """Return the sum of all numbers, less than n , which are palindromic in |
| 41 | base 10 and base 2. |
| 42 | |
| 43 | >>> solution(1000000) |
| 44 | 872187 |
| 45 | >>> solution(500000) |
| 46 | 286602 |
| 47 | >>> solution(100000) |
| 48 | 286602 |
| 49 | >>> solution(1000) |
| 50 | 1772 |
| 51 | >>> solution(100) |
| 52 | 157 |
| 53 | >>> solution(10) |
| 54 | 25 |
| 55 | >>> solution(2) |
| 56 | 1 |
| 57 | >>> solution(1) |
| 58 | 0 |
| 59 | """ |
| 60 | total = 0 |
| 61 | |
| 62 | for i in range(1, n): |
| 63 | if is_palindrome(i) and is_palindrome(bin(i).split("b")[1]): |
| 64 | total += i |
| 65 | return total |
| 66 | |
| 67 | |
| 68 | if __name__ == "__main__": |
no test coverage detected