def is_lychrel(n): count = 1 n += int(str(n)[::-1]) while not is_palindrome(n) and count < 50: n += int(str(n)[::-1]) count += 1 return not is_palindrome(n)
def largest_palindrome_product(minimum=100, maximum=999): """ exhaustively finds the largest palindromic product in a range minimum, maximum (int): defines range, inclusive returns (int): solution """ stub = Stub() #stub.start() candidate_solution = None palindrome_products = [] candidate_factors = [None, None] for i in range(maximum, minimum-1, -1): for j in range(i, minimum-1, -1): product = i*j if is_palindrome(product): palindrome_products.append(product) if product > candidate_solution: candidate_solution = product candidate_factors = [i, j] stub.msg(candidate_factors, "factors") return candidate_solution
def is_lychrel(n): i = 0 while i < 50: n += int(''.join(list(reversed(digits(n))))) if is_palindrome(digits(n)): return False i += 1 return True
def main(): count = 0 for i in range(1, 10000): for _ in range(50): i = step(i) if euler.is_palindrome(i): break else: count += 1 return count
def main(): maximum = 0 for i in range(10**DIGITS - 1, 10**(DIGITS - 1) - 1, -1): for j in range(10**DIGITS - 1, i - 1, -1): prod = i * j if prod > maximum: if euler.is_palindrome(prod): maximum = prod else: break return maximum
def main(): s = set() for b in range(1, 10000): temp = b * (b + 1) * (2 * b + 1) for a in range(b - 2, -1, -1): result = (temp - a * (a + 1) * (2 * a + 1)) // 6 if result > LIMIT: break if euler.is_palindrome(result): s.add(result) return sum(s)
def compute(): ways = {} for i in range(1, int(limit ** 0.5)): for j in range(1, int(limit ** 0.33)): temp = i ** 2 + j ** 3 if is_palindrome(temp): if temp in ways: ways[temp] += 1 else: ways[temp] = 1 return sum([w for w in ways if ways[w] == 4][:5])
def main(): total = 0 for n in range(1000000): if euler.is_palindrome(str(n)) and euler.is_palindrome("{0:b}".format(n)): total += n print(total)
# -*- coding:utf-8 -*- """Project Euler problem 36""" from euler import is_palindrome sm = 0 for i in range(1000000): if is_palindrome(str(i)) and is_palindrome(str(bin(i))[2:]): sm += i print("Answer: " + str(sm))
from euler import is_palindrome print max(i * j for i in xrange(999, 900, -1) for j in xrange(999, i, -1) if is_palindrome(i * j))
# coding=utf-8 ''' Problem 36 31 January 2003 The decimal number, 585 = 10010010012 (binary), is palindromic in both bases. Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2. (Please note that the palindromic number, in either base, may not include leading zeros.) ''' import euler print sum(n for n in range(1, 10**6+1) if (euler.is_palindrome(n) and euler.is_palindrome(bin(n)[2:])))
''' from euler import is_palindrome multiples = set() # Creating the set of all 3-digit multiples. for factor1 in range(100, 1000): # For the second loop, we do not need to search and number lower # than the number we're currently on in the first loop. We have already # multiplied those two in a previous loop. # E.g. when factor1 = 102, we do not need to multiply it by factor2 = 101 # because when factor1 = 101, there was an interation when factor2 = 102. # 102 * 101 = 101 * 102 for factor2 in range(factor1, 1000): multiples.add(factor1 * factor2) smallest_multiple = 100 * 100 largest_multiple = 999 * 999 palindromes = set() # Creating the set of all palindromes. for number in range(smallest_multiple, largest_multiple): if is_palindrome(number) == True: palindromes.add(number) both = multiples.intersection(palindromes) answer = max(both) print(f"the largest palindromic product of two 3-digit numbers is {answer}.")
from euler import is_palindrome total = 0 for n in range(1000000): if is_palindrome(str(n)) and is_palindrome(str(bin(n))[2:]): total += n print(total)
def palin_gen(): for j in xrange(999, 900, -1): for k in xrange(999, 900, -1): n = j * k if euler.is_palindrome(n): yield n
def compute(): return sum([n for n in range(10**6) if is_palindrome(n) and is_palindrome(str(bin(n))[2:])])
import sys sys.path.append("..") from euler import is_palindrome upper = 1000000 double_palindromes = [] for i in range(upper): digits = list(str(i)) if is_palindrome(digits): base2 = list(format(i, 'b')) if is_palindrome(base2): double_palindromes.append(i) result = sum(double_palindromes) print(double_palindromes) print(result)
def test_is_palindrome(self): """Basic palindrome test""" self.assertTrue(euler.is_palindrome(1001))
import sys sys.path.append("..") from euler import is_palindrome largest = 9009 for i in range(100, 1000): for j in range(i, 1000): product = i * j if product > largest and is_palindrome(product): largest = product print(largest)
# -*- coding:utf-8 -*- """Project Euler problem 55""" from euler import is_palindrome c = 0 for i in range(10000): p = i for j in range(50): p = p + int(str(p)[::-1]) if is_palindrome(p): break else: c += 1 print("Answer: " + str(c))
#!/usr/bin/env python #Find the largest palindrome made from the product of two 3-digit numbers. import euler product = 0 palindrome = 0 for n in range(999, 100, -1): for x in range(100, 999, 1): product = n * x if euler.is_palindrome(str(product)) == True: if product > palindrome: palindrome = product print(palindrome)
def compute(): return max([i * j for i in range(100, 1000) for j in range(100, 1000) if is_palindrome(i * j)])
#!/usr/bin/env python #Find the largest palindrome made from the product of two 3-digit numbers. import euler product = 0 palindrome = 0 for n in range(999,100,-1): for x in range(100,999,1): product = n * x if euler.is_palindrome(str(product)) == True: if product > palindrome: palindrome = product print(palindrome)