Project Euler 44 - Pentagon numbers

Official link: https://projecteuler.net/problem=44

Thought Process

P(n) is an increasing function, therefore we want P(k) and P(j) to be as close to each other as possible to minimise their absolute difference.

I made 2 functions

  1. is_pentagonal(x)

    • Take's an integer x and tests if this number is a pentagonal number by taking the inverse, see below to see how to derive the inverse function

  2. compute()

    • initialise k = 1, start a while loop, then a for loop goes through j from 1 to k, it will then test if P(k) - P(j) and P(k) + P(j) are both pentagonal, as soon as I find one I know it will be the minimum solution

Interactive Code

No interactive code for this one, code is given below