Beispiel #1
0
def eul55():
    """How many Lychrel numbers are there below n = ten-thousand?"""
    lycs = []
    for num in range(1, 10000):
        i = num
        found, itr = False, 0
        while not found and itr < 50:
            i += eul.reverse_digits(i)
            found = eul.palindrome(i)
            itr += 1
        if not found:
            lycs.append(num)
    return len(lycs)
Beispiel #2
0
def eul4(n):
    """Find the largest palindrome made from the product of two n=3-digit numbers."""
    return max([x * y for x in range(10 ** (n - 1), 10 ** n) for y in
                range(10 ** (n - 1), 10 ** n) if eul.palindrome(x * y)])
Beispiel #3
0
def eul36():
    """Find the sum of all numbers, less than n = one million, which are palindromic in base 10 and base 2."""
    return sum([x for x in range(1, 1000001) if eul.palindrome(x) and eul.palindrome(str(bin(x))[2:])])
Beispiel #4
0
def eul4():
    """Find the largest palindrome made from the product of two 3-digit numbers."""
    return max([x * y for x in range(100, 1000) for y in range(100, 1000) if eul.palindrome(x * y)])