def problem_4(): largest_product = 0 for i in range(100, 999): for j in range(100, 999): product = i*j if is_palindrome(product): if product > largest_product: largest_product = product return largest_product
def is_lychrel(n, iteration): # consider it lychrel if it's the 50th iteration if iteration >= 50: _lychrels[n] = True # if it's a palindrome and it's the sum of another number and its reverse, # return False elif iteration > 0 and util.is_palindrome(str(n)): _lychrels[n] = False # if we already know this to be a lychrel number, we return True elif _lychrels.get(n): pass # otherwise, we have no idea yet else: # let's try this again _lychrels[n] = is_lychrel(n + int(str(n)[::-1]), iteration + 1) return _lychrels[n]
def problem4(m): return max(n for n in (a * b for a in xrange(m, -1, -1) for b in xrange(m, -1, -1)) if util.is_palindrome(str(n)))
def problem036(maximum): return sum(i for i in xrange(1, maximum, 2) if util.is_palindrome(str(i)) and util.is_palindrome(bin(i)))
#!/usr/bin/env python import itertools import util print(max( [x*y for x, y in itertools.product(range(100, 999), repeat=2) if util.is_palindrome(x*y)] ))
""" Project Euler Problem 4 ======================= 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. """ from util import is_palindrome list = range(100, 1000) prods = [n * m for n in list for m in list] prods.sort() prods.reverse() largest = None for p in prods: if is_palindrome(str(p)): largest = p break print largest
def is_palindrome_bin(n): return util.is_palindrome(util.dec2bin(n))
def is_palindrome_num(n): return util.is_palindrome(str(n))
#!/usr/bin/env python from util import is_palindrome if __name__ == "__main__": cur_max_xy = 0 max_x = 0 max_y = 0 for x in xrange(100, 1000): for y in xrange(100, 1000): res = x*y if is_palindrome(res) and res > cur_max_xy: max_x = x max_y = y cur_max_xy = res print 'x:',max_x print 'y:',max_y print 'max pali:',cur_max_xy
word_list = filtered_string.split(" ") vowels = "aeiouAEIOU" contains_palindrome = False first_palindrome = None letter_count = 0 uppercase_count = 0 lowercase_count = 0 word_count = 0 vowel_count = 0 consonant_count = 0 for word in word_list: if not contains_palindrome: if is_palindrome(word): contains_palindrome = True first_palindrome = word if is_palindrome_anagram(word): print(word, "is palindrome anagram.") else: print(word, "is not palindrome anagram.") letter_count += len(word) has_number = False for c in word: if c.isdigit(): has_number = True else:
#!/usr/bin/env python from util import is_palindrome if __name__ == "__main__": cur_max_xy = 0 max_x = 0 max_y = 0 for x in xrange(100, 1000): for y in xrange(100, 1000): res = x * y if is_palindrome(res) and res > cur_max_xy: max_x = x max_y = y cur_max_xy = res print "x:", max_x print "y:", max_y print "max pali:", cur_max_xy
from util import is_palindrome pali_sum = 0 for i in range(1, 1000000): str_bin = str(bin(i)).lstrip("0b") str_10 = str(i) if is_palindrome(str_10) and is_palindrome(str_bin): print(str_bin,str_10) pali_sum += i print(pali_sum)
#! /usr/bin/python import util largest_palindrome = 0 for i in range(100, 1000): for j in range(100, 1000): prod = i * j if util.is_palindrome(prod) and prod > largest_palindrome: largest_palindrome = prod print(largest_palindrome)