Ejemplo n.º 1
0
def eul44():
    """Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference are pentagonal
    and D = |Pk − Pj| is minimised; what is the value of D?"""
    for i in range(2,3000):
        n = i * (3 * i - 1) / 2
        for j in range(i - 1, 0, -1):
            m = j * (3 * j - 1) / 2
            if eul.pentagonal(n - m) and eul.pentagonal(n + m):
                return int(n-m)
Ejemplo n.º 2
0
def eul45():
    """Find the next triangle number that is also pentagonal and hexagonal."""
    i = 143
    while i:
        i += 1
        hexagonal = i * (2 * i - 1)
        if eul.pentagonal(hexagonal):
            return hexagonal