This commit is contained in:
David Doblas Jiménez
2021-09-20 17:53:15 +02:00
parent ad6c4e4cd2
commit 7c8165d9c2
50 changed files with 2264 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
#!/usr/bin/env python3
"""
Created on 08 Apr 2021
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for problem 36 of Project Euler
https://projecteuler.net/problem=36
"""
from utils import timeit
def is_palidrome(num):
return str(num) == str(num)[::-1]
@timeit("Problem 36")
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 36: {compute()}")