Solve problem 145

main
Felix Martin 2021-04-21 16:30:54 -04:00
parent c281f9e9c0
commit fc66fce8ff
1 changed files with 29 additions and 0 deletions

29
python/e145.py Normal file
View File

@ -0,0 +1,29 @@
def reversible(n):
n_rev_str = str(n)[::-1]
if n_rev_str.startswith("0"):
return False
n_rev = int(n_rev_str)
ds = str(n + n_rev)
for d in ds:
if int(d) % 2 == 0:
return False
return True
def euler_145():
# pure bruteforce, took about four minutes wity pypy
count = 0
counted = set()
for i in range(10**9):
if not i in counted and reversible(i):
count += 1
counted.add(i)
return count
if __name__ == "__main__":
solution = euler_145()
print("e145.py: " + str(solution))
assert(solution == 608720)