<jupyter_start><jupyter_text>Problem 44Pentagonal 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 are pentagonal and `D = |P_k − P_j|` is minimised; what is the value of `D`?<jupyter_code>import math
class Solution:
    def __init__(self):
        pass
    def is_pentagonal(self, x):
        # See test for pentagonal numbers
        # https://en.wikipedia.org/wiki/Pentagonal_number
        n = math.sqrt(24 * x + 1) + 1
        return n/6 == n//6
    def p(self, n):
        return n * (3*n - 1) // 2
    def each_jk(self, limit):
        for gap in range(1,limit):
            for j in range(1,limit+gap):
                k = j+gap
                yield (j,k)
    def search(self, limit):
        for (j,k) in self.each_jk(limit):
            P_j = self.p(j)
            P_k = self.p(k)
            D = P_k - P_j
            S = P_k + P_j
            if self.is_pentagonal(D) and self.is_pentagonal(S):
                return (j,k,D)
s = Solution()
ans = s.search(10000)
print("Answer:", ans[2])
print("Where j=%d and k=%d"%(ans[0], ans[1]))<jupyter_output>Answer: 5482660
Where j=1020 and k=2167
{'fraction_non_alphanumeric': 0.13462922966162708, 'fraction_numerical': 0.05327573794096472, 'mean_word_length': 2.3413461538461537, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '222014', 'license': 'MIT', 'n_tokens_mistral': 560, 'n_tokens_neox': 500, 'n_words': 159, 'path': 'solutions/jupyter/problem-44.ipynb', 'repo_name': 'danui/project-euler', 'size': '1389'}