Skip to content

Instantly share code, notes, and snippets.

@tarsisazevedo
Created July 6, 2011 03:29
Show Gist options
  • Save tarsisazevedo/1066496 to your computer and use it in GitHub Desktop.
Save tarsisazevedo/1066496 to your computer and use it in GitHub Desktop.
euler 36
from unittest import TestCase, main
class TestDecimalBinPalindromicsNumbers(TestCase):
def test_585_and_1001001001_are_palindromic(self):
self.assertTrue(is_palindromic_with_base_2(number=585))
def test_sum_of_all_palindromic_dec_bin_number_are_1000000(self):
self.assertEquals(sum_all_palindromic_dec_bin_of_numbers_to(1000000), 872187)
def is_palindromic_with_base_2(number):
str_number = str(number)
bin_number = bin(number)[2:]
if str_number == str_number[::-1] and bin_number == bin_number[::-1]:
return True
return False
def sum_all_palindromic_dec_bin_of_numbers_to(number):
return sum([x for x in range(1, number+1) if is_palindromic_with_base_2(x)])
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment