Advertisement
danchaofan

Euler #39

Dec 6th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. def pythagorean(leg, p):
  2.     hypotenuse = int(p/3)
  3.     leg2 = p - hypotenuse - leg
  4.     while True:
  5.         if (leg ** 2 + leg2 ** 2) == hypotenuse ** 2:
  6.             return True
  7.         leg2 -= 1
  8.         hypotenuse += 1
  9.         if hypotenuse == p:
  10.             return False
  11. best, bestx, runningtotal = 0, 0, 0
  12. for x in range(3, 1001):
  13.     print(x, best)
  14.     for y in range(int(x/3)+1):
  15.         if pythagorean(y, x):
  16.             runningtotal += 1
  17.     if runningtotal > best:
  18.         best = runningtotal
  19.         bestx = x
  20.     runningtotal = 0
  21. print(bestx)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement