def compute(): i = 2 while True: i += 1 m = i * (3 * i - 1) // 2 for j in range(2, i): n = j * (3 * j - 1) // 2 if is_pentagonal(m+n) and is_pentagonal(m-n): return m - n
# 1533776805 import euler n = 144 while True: h = n * (2 * n - 1) if euler.is_pentagonal(h) and euler.is_triangular(h): print h break n += 1
def compute(): n = 144 while not (is_triangular(n * (2 * n - 1)) and is_pentagonal(n * (2 * n - 1))): n += 1 return n * (2 * n - 1)
# 5482660 import euler i = 1 p = [0] m = None while m is None: p.append(i * (3 * i - 1) / 2) if p[i] % 2 == 0: j = 1 while i > j: if p[j] % 2 == 0 and euler.is_pentagonal(p[i] - p[j]) and \ euler.is_pentagonal(p[i] + p[j]): m = p[i] - p[j] break j += 1 i += 1 print m
from itertools import count, takewhile from euler import pentagonal, is_pentagonal result = () pentagonals_generated = set() for n in count(1): pentagon_n = pentagonal(n) pentagonals_generated.add(pentagon_n) for pentagon_sub_n in takewhile(lambda p_sub_n: p_sub_n < pentagon_n, pentagonals_generated): pentagon_diff = pentagon_n - pentagon_sub_n if pentagon_diff in pentagonals_generated: pentagon_sum = pentagon_n + pentagon_sub_n if is_pentagonal(pentagon_sum): result = (pentagon_diff, n, pentagon_n, pentagon_sub_n, pentagon_sum) break else: continue break print "D: %d, n: %d, pentagon_n: %d, pentagon_sub_n: %d, pentagon_sumb: %d" % result
from itertools import count from euler import pentagonal, is_pentagonal result = () for n in count(1): pentagon_n = pentagonal(n) for sub_n in xrange(1, n): pentagon_sub_n = pentagonal(sub_n) pentagon_diff = pentagon_n - pentagon_sub_n if is_pentagonal(pentagon_diff): pentagon_sum = pentagon_n + pentagon_sub_n if is_pentagonal(pentagon_sum): result = (pentagon_diff, n, sub_n, pentagon_n, pentagon_sub_n, pentagon_sum) break else: continue break print "D: %d, n: %d, sub_n: %d, pentagon_n: %d, pentagon_sub_n: %d, pentagon_sumb: %d" % result