def problem36(): """ Double-base palindromes Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2. """ return sum(x for x in range(1, 1000000) if mathhelper.is_palindromic(x) and mathhelper.is_palindromic(int(bin(x)[2:])))
def test_is_palindromic(self): self.assertEqual(mathhelper.is_palindromic(-1), True) self.assertEqual(mathhelper.is_palindromic(0), True) self.assertEqual(mathhelper.is_palindromic(1), True) self.assertEqual(mathhelper.is_palindromic(11), True) self.assertEqual(mathhelper.is_palindromic(13), False) self.assertEqual(mathhelper.is_palindromic(131), True) self.assertEqual(mathhelper.is_palindromic(199991), True) self.assertEqual(mathhelper.is_palindromic(1999991), True) self.assertEqual(mathhelper.is_palindromic(234667556), False)
def problem4(): """ Largest palindrome product A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. """ return max( x * y for (x, y) in itertools.product(range(100, 1000), repeat=2) if mathhelper.is_palindromic(x * y))