From fc66fce8ff2b4ab17923d5946e7f9128db60ef11 Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Wed, 21 Apr 2021 16:30:54 -0400 Subject: [PATCH] Solve problem 145 --- python/e145.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 python/e145.py diff --git a/python/e145.py b/python/e145.py new file mode 100644 index 0000000..755fbc9 --- /dev/null +++ b/python/e145.py @@ -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) +