Example #1
0
File: p44.py Project: lukeleslie/pe
def answer():
	# iterate through pentagonal differences until we match the 
	# pentagonal number and sum criteria. We use the observation
	# that the difference from one pentagonal number to another must be > 1,
	# hence we only need check those numbers less than or equal to the difference
	n = 1
	while True:
		diff = n * (3.0 * n - 1.0) / 2.0
		for i in xrange(1, n + 1):
			m = i * (3.0 * i - 1.0) / 2.0
			if is_pentagonal_number(m + diff) and is_pentagonal_number(m + m + diff):
				return diff
		n += 1
Example #2
0
File: p45.py Project: lukeleslie/pe
def answer():
	n = 286
	while True:
		n_t = n * (n + 1.0) / 2.0
		if is_hexagonal_number(n_t) and is_pentagonal_number(n_t):
			return n_t

		n += 1
Example #3
0
def find_pentagonal_and_hexagonal(lower_bound):
    n = lower_bound + 1

    while (True):
        hn = hexagonal_number(n)

        if is_pentagonal_number(hn):
            return hn

        n += 1
Example #4
0
from helpers import test, hexagonal_number, is_pentagonal_number, is_hexagonal_number


def find_pentagonal_and_hexagonal(lower_bound):
    n = lower_bound + 1

    while (True):
        hn = hexagonal_number(n)

        if is_pentagonal_number(hn):
            return hn

        n += 1


test(hexagonal_number(1), 1)
test(hexagonal_number(2), 6)
test(hexagonal_number(3), 15)

test(is_pentagonal_number(22), True)
test(is_pentagonal_number(24), False)
test(is_hexagonal_number(45), True)
test(is_hexagonal_number(46), False)

test(find_pentagonal_and_hexagonal(1), 40755)
print find_pentagonal_and_hexagonal(143)