예제 #1
0
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
예제 #2
0
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]
예제 #3
0
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)))
예제 #4
0
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)))
예제 #5
0
파일: 4.py 프로젝트: 5225225/project_euler
#!/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)]
))
예제 #6
0
"""
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
예제 #7
0
def is_palindrome_bin(n):
    return util.is_palindrome(util.dec2bin(n))
예제 #8
0
def is_palindrome_num(n):
    return util.is_palindrome(str(n))
예제 #9
0
파일: e_0004.py 프로젝트: jtlai0921/euler.
#!/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
예제 #10
0
        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:
예제 #11
0
파일: e_0004.py 프로젝트: mahmoud/euler
#!/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
예제 #12
0
파일: 0036.py 프로젝트: Saiyan/euler
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)
예제 #13
0
파일: 0004.py 프로젝트: Saiyan/euler
#! /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)