{"id":121,"date":"2014-04-07T16:58:08","date_gmt":"2014-04-07T23:58:08","guid":{"rendered":"http:\/\/willclausen.com\/?p=121"},"modified":"2014-04-10T14:53:37","modified_gmt":"2014-04-10T21:53:37","slug":"project-euler-problem-36","status":"publish","type":"post","link":"http:\/\/willclausen.com\/?p=121","title":{"rendered":"Project Euler Problem 36"},"content":{"rendered":"<p>Another one bites the dust! I worked with my brother David on this one, so a big thanks to him for his help.<\/p>\n<p>Here&#8217;s the problem:<br \/>\nThe decimal number, 585 = 10010010012 (binary), is palindromic in both bases.<\/p>\n<p>Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.<\/p>\n<p>(Please note that the palindromic number, in either base, may not include leading zeros.)<\/p>\n<p><strong>My Solution:<\/strong><\/p>\n<pre class=\"brush: python; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n# Authors: William and David Clausen\r\n# Date: 8\/4\/13\r\n# Description: Project Euler Problem 36\r\n\r\n# Function that solves Project Euler Problem 36.\r\ndef problem36(limit):\r\n        total = 0\r\n        check = 1\r\n        while check &lt; limit:\r\n                strCheck = str(check)\r\n                # Take advantage of helpful format function to change the\r\n                # checked number into a string in base 2!\r\n                strBase2 = format(check, 'b')\r\n\r\n                if isPalindrome(strBase2) and isPalindrome(strCheck):\r\n                        total += check\r\n\r\n                check += 2\r\n\r\n        return total\r\n\r\n# This function determines if a given string is a palindrome. O(n).\r\ndef isPalindrome(string):\r\n        for x in range(len(string)\/2):\r\n                if string&#x5B;x] != string&#x5B;-x - 1]:\r\n                        return False\r\n\r\n        return True\r\n                        \r\nif __name__ == &quot;__main__&quot;:\r\n        answer = problem36(1000000)\r\n        print &quot;Answer is: &quot; + str(answer)\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Another one bites the dust! I worked with my brother David on this one, so a big thanks to him for his help. Here&#8217;s the problem: 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[30,42],"class_list":["post-121","post","type-post","status-publish","format-standard","hentry","category-updates","tag-problem-36","tag-project-euler"],"_links":{"self":[{"href":"http:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/posts\/121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/willclausen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=121"}],"version-history":[{"count":3,"href":"http:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/posts\/121\/revisions"}],"predecessor-version":[{"id":124,"href":"http:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/posts\/121\/revisions\/124"}],"wp:attachment":[{"href":"http:\/\/willclausen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/willclausen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/willclausen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}