Skip to content

Instantly share code, notes, and snippets.

@igorvanloo
Created July 24, 2021 07:02
Show Gist options
  • Select an option

  • Save igorvanloo/067e89bf27b655784d0238cf261260de to your computer and use it in GitHub Desktop.

Select an option

Save igorvanloo/067e89bf27b655784d0238cf261260de to your computer and use it in GitHub Desktop.
Problem 44
def is_pentagonal(x):
#Take the inverse function to test whether or not a number is pentagonal
if (1+(24*x+1)**0.5) % 6 == 0:
return True
return False
def compute():
k = 1
while True:
for j in range(1,k): # this ensures that a > b therefore a-b is minimised
a = int((k/2)*(3*k-1))
b = int((j/2)*(3*j-1))
if is_pentagonal(a+b) == True and is_pentagonal(abs(a-b)) == True: #Once we find given condition we are done
print(k,j)
return (abs(a-b))
k += 1 #Keep increasing till solution is found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment