+Pentagonal numbers are generated by the formula, P_(n)=n(3n−1)/2. The
+first ten pentagonal numbers are:
+1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...
+It can be seen that P_(4) + P_(7) = 22 + 70 = 92 = P_(8). However,
+their difference, 70 − 22 = 48, is not pentagonal.
+Find the pair of pentagonal numbers, P_(j) and P_(k), for which their
+sum and difference is pentagonal and D = |P_(k) − P_(j)| is minimised;
+ return n * (3*n - 1) / 2
+def printinfo(pent, k, j):
+ print 'P(%d) = %d, P(%d) = %d, sum = %d %s, diff = %d %s' % (
+ k, pent[k], j, pent[j],
+ pent[k] + pent[j], pent[k] + pent[j] in pent,
+ pent[k] - pent[j], pent[k] - pent[j] in pent,)
+ Since the sequence of pentagonals is increasing, as soon as the
+ difference between terms is greater than D, the existing min
+ difference is guarnateed to be the minimum for the whole sequence.
+ if pent[k] - pent[j] in pent:
+ while pent[-1] < pent[k] + pent[j]:
+ genpentto(pent, pent[k] + pent[j])
+ if pent[k] + pent[j] in pent:
+ diff.append(pent[k] - pent[j])
+ # TODO: Fix the logic to test if D is really minimized.
+ print k, len(pent), pent[-1], pent[-1] - pent[-2]
+if __name__ == '__main__':