Advertisement
benlloydjones

Project Euler 44

Jul 4th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. def isPent(n):
  2.     a = 3
  3.     b = 1
  4.     c = -2 * n
  5.     d = (b ** 2) - (4 * a * c)
  6.     answer = (-b - (d ** 0.5)) / (2 * a)
  7.     if str(abs(answer))[-1] == '0':
  8.         return True
  9.     else:
  10.         return False
  11.  
  12. def penta(n):
  13.     numb = []
  14.     for x in range(1, n + 1, 1):
  15.         pent = int(x * ((3 * x) - 1) / 2)
  16.         numb.append(pent)
  17.     return numb
  18.  
  19. def PE44():
  20.     possibles = penta(10000)
  21.     answers = []
  22.     for x in possibles:
  23.         for y in possibles:
  24.             if isPent(x + y) and isPent(x - y):
  25.                 answers.append(abs(x - y))
  26.     return answers
  27.  
  28. PE44()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement