Esempio n. 1
0
def main():
    i = 1
    pentagonals = []

    while True:
        penta = i * (3 * i - 1) // 2

        for p in pentagonals:
            if is_pentagonal(penta - p) and is_pentagonal(penta + p):
                print(penta - p)
                return

        i += 1
        pentagonals += [penta]
Esempio n. 2
0
def euler45():
    n = 2
    while True:
        x = n * (2 * n - 1)
        if is_triangular(x) and is_pentagonal(x) and n != 143:
            return x
        n += 1
Esempio n. 3
0
def main():
    cnt = 0

    for num in hexagonal_numbers():
        if is_pentagonal(num):  # Every hexagonal number is a triangular number
            cnt += 1
            if cnt == 3:
                return num
Esempio n. 4
0
def main():
    # P(n+k)-P(n) = 3kn + P(k), P(n+k)-P(n) = P(m)
    pm = 1
    for m in count(1):
        if not pm & 1:  # both numbers must be even
            pk = 1
            for k in range(1, m):
                if not (pm - pk) % (3 * k):
                    n = (pm - pk) // (3 * k)
                    if is_pentagonal(pm + n * (3 * n - 1)):
                        return pm
                pk += 3 * k + 1
        pm += 3 * m + 1
Esempio n. 5
0
def main():
    # P(n+k)-P(n) = 3kn + P(k), P(n+k)-P(n) = P(m)
    pm = 1
    for m in count(1):
        if not pm & 1:  # both numbers must be even
            pk = 1
            for k in range(1, m):
                if not (pm - pk) % (3*k):
                    n = (pm - pk) // (3*k)
                    if is_pentagonal(pm + n*(3*n - 1)):
                        return pm
                pk += 3*k + 1
        pm += 3*m + 1
Esempio n. 6
0
def num_type(n):
    types = list()
    if utils.is_triangle(n):
        types.append('A')
    if utils.is_square(n):
        types.append('B')
    if utils.is_pentagonal(n):
        types.append('C')
    if utils.is_hexagonal(n):
        types.append('D')
    if utils.is_heptagonal(n):
        types.append('E')
    if utils.is_octagonal(n):
        types.append('F')
    return types
Esempio n. 7
0
def main():
    i = 1
    cnt = 0

    while True:
        triangular = i * (i + 1) // 2

        if is_pentagonal(triangular) and is_hexagonal(triangular):
            print(triangular)
            cnt += 1

            if cnt == 3:
                return

        i += 1
Esempio n. 8
0
    def test_is_pentagonal(self):
        self.assertTrue(is_pentagonal(1))
        self.assertFalse(is_pentagonal(2))
        self.assertTrue(is_pentagonal(5))
        self.assertFalse(is_pentagonal(15))

        n = 10**15
        p = nth_pentagonal(n)
        self.assertTrue(is_pentagonal(p))
        self.assertFalse(is_pentagonal(p + 2))
Esempio n. 9
0
    def test_is_pentagonal(self):
        self.assertTrue(is_pentagonal(1))
        self.assertFalse(is_pentagonal(2))
        self.assertTrue(is_pentagonal(5))
        self.assertFalse(is_pentagonal(15))

        n = 10**15
        p = nth_pentagonal(n)
        self.assertTrue(is_pentagonal(p))
        self.assertFalse(is_pentagonal(p + 2))
Esempio n. 10
0
def criteria(n, m):
    return (is_pentagonal(pentagonal(n) - pentagonal(m))
            and is_pentagonal(pentagonal(n) + pentagonal(m)))
Esempio n. 11
0
def criteria(n,m):
    return (is_pentagonal(pentagonal(n)-pentagonal(m)) and
            is_pentagonal(pentagonal(n)+pentagonal(m)))
Esempio n. 12
0
import utils


def next_hexagonal(sequence):
    n = len(sequence) + 1
    return utils.nth_hexagonal(n)


hexagonals = utils.Sequence(next_hexagonal)

lower_bound = 40755
for num in hexagonals.iterate():
    if utils.is_triangular(num) and utils.is_pentagonal(num):
        print(num, 'is triangular, pentagonal, and hexagonal')
        if num > lower_bound:
            break