Esempio n. 1
0
def problem_44():

    # upper limit determined experimentally. Haven't found an analytical way to determine it
    pentagonals = list(pentagonal_numbers(count=3000))

    candidates = list()
    for a in pentagonals:
        for b in pentagonals:
            if a == b:
                continue
            if is_pentagonal(abs(a - b)) and is_pentagonal(a + b):
                # the first such pair we find should be smallest difference, so we can finish
                print(abs(a - b))
                return
Esempio n. 2
0
def problem_45():

    # We can ignore the triangle number aspect of the problem altogether, since all hexagonal
    # numbers are also triangular numbers

    # get an iterator for hexagonal numbers, and skip them up to 40755, since we want to identify
    # a number after that point
    hexagonals = hexagonal_numbers()
    while next(hexagonals) < 40755:
        pass

    for n in hexagonals:
        if is_pentagonal(n):
            print(n)
            break