コード例 #1
0
ファイル: allEulerSols.py プロジェクト: hayleyguillou/eul
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)
コード例 #2
0
ファイル: eul004.py プロジェクト: hayleyguillou/eul
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)])
コード例 #3
0
ファイル: allEulerSols.py プロジェクト: hayleyguillou/eul
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:])])
コード例 #4
0
ファイル: allEulerSols.py プロジェクト: hayleyguillou/eul
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)])