Files
project-euler/src/Python/Problems001-050/Problem036.py
2023-04-01 15:57:07 +02:00

39 lines
749 B
Python

#!/usr/bin/env python
"""
Created on 08 Apr 2021
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for problem 036 of Project Euler
https://projecteuler.net/problem=36
"""
from utils import timeit
def is_palidrome(num):
return str(num) == str(num)[::-1]
@timeit("Problem 036")
def compute():
"""
The decimal number, 585 = 1001001001_2 (binary), is palindromic
in both bases.
Find the sum of all numbers, less than one million, which are palindromic
in base 10 and base 2.
"""
ans = 0
for i in range(1, 1_000_001, 2):
if is_palidrome(i) and is_palidrome(bin(i)[2:]):
ans += i
return ans
if __name__ == "__main__":
print(f"Result for Problem 036: {compute()}")