Solution to problem 36
This commit is contained in:
parent
1def60b631
commit
9ffd20082d
35
src/Python/Problem036.py
Normal file
35
src/Python/Problem036.py
Normal 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()}")
|
Loading…
x
Reference in New Issue
Block a user