From 9ed60ba882c7b6a07b7b951447558710fcbdcc4b Mon Sep 17 00:00:00 2001 From: Daniel Ingram Date: Mon, 2 Apr 2018 12:20:53 -0400 Subject: [PATCH] Solution to Problem 36 --- Project Euler/Problem 36/sol1.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Project Euler/Problem 36/sol1.py diff --git a/Project Euler/Problem 36/sol1.py b/Project Euler/Problem 36/sol1.py new file mode 100644 index 000000000..d78e7e59f --- /dev/null +++ b/Project Euler/Problem 36/sol1.py @@ -0,0 +1,30 @@ +from __future__ import print_function +''' +Double-base palindromes +Problem 36 +The decimal number, 585 = 10010010012 (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. + +(Please note that the palindromic number, in either base, may not include leading zeros.) +''' +try: + xrange #Python 2 +except NameError: + xrange = range #Python 3 + +def is_palindrome(n): + n = str(n) + + if n == n[::-1]: + return True + else: + return False + +total = 0 + +for i in xrange(1, 1000000): + if is_palindrome(i) and is_palindrome(bin(i).split('b')[1]): + total += i + +print(total) \ No newline at end of file