예제 #1
0
def is_lychrel(n, i=0):
  if i > 50: return True
  reverse = int(str(n)[::-1])
  s = n + reverse
  if euler.is_palindrome(s): return False
  else: return is_lychrel(s, i+1)
예제 #2
0
 
"""
Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
"""

from lib import euler

# seems easy enough...


def to_binary(n):
  s = ''
  if n == 0: return '0'
  while n:
    s += '1' if n % 2 else '0'
    n = n >> 1
  return s[::-1]

palindromes = []
for i in xrange(10**6):
  if euler.is_palindrome(i) and euler.is_palindrome(to_binary(i)):
    palindromes += [i]

print sum(palindromes)

예제 #3
0
#!/usr/bin/env python

"""Find the largest palindrome made from the product of two 3-digit numbers."""

from lib import euler

largest = 0
for i in xrange(100, 1000):
  for j in xrange(100, 1000):
    product = i*j
    if euler.is_palindrome(product) and product > largest:
      largest = product

print largest