def test_is_palindrome(self): self.assertTrue(is_palindrome(3)) self.assertFalse(is_palindrome(34)) self.assertTrue(is_palindrome(33)) self.assertFalse(is_palindrome(221)) self.assertTrue(is_palindrome(212)) self.assertTrue(is_palindrome(21212)) self.assertTrue(is_palindrome(199383991))
def is_lychrel_number(n): i = 0 while i < 50: i += 1 t = n + int(str(n)[::-1]) if is_palindrome(t): return False n = t return True
def is_lychrel(n): for i in xrange(24): n += reverse_num(n) if is_palindrome(n): return False return True
def is_double_base_palindrome(n): return n > 0 and is_palindrome(str(n)) and is_palindrome(int(bin(n)[2:]))
#coding:utf-8 ''' Created on 2016年1月3日 @author: robinjia @email: [email protected] ''' from common import is_palindrome if __name__ == "__main__": result = 1 for i in range(100, 1000): for j in range(i, 1000): temp = i * j if is_palindrome(temp) and temp > result: result = temp print(result)
#!/usr/bin/env python from common import is_palindrome s = 0 for i in range(1, 1000000): if is_palindrome(i): b = format(i, 'b') if is_palindrome(b): s += i print(s)
#!/usr/bin/env python # Title: Largest palindrome product # Description: Find the largest palindrome made from the product of two 3-digit numbers from common import is_palindrome from sys import exit largest = 1 for i in range(999, 100, -1): for j in range(999, 100, -1): if i*j > largest and is_palindrome(i*j): largest = i*j print largest