Skip to content

Instantly share code, notes, and snippets.

@igorvanloo
Created January 29, 2025 09:39
Show Gist options
  • Save igorvanloo/a7a164702902ffad722412ea0e31ef14 to your computer and use it in GitHub Desktop.
Save igorvanloo/a7a164702902ffad722412ea0e31ef14 to your computer and use it in GitHub Desktop.
p142
def is_sq(x):
sqrt = (x ** (1 / 2))
if round(sqrt) ** 2 == x:
return True
return False
def compute():
for b in range(1, 1000):
for a in range(b + 2, 1000, 2):
x = (a*a + b*b)//2
y = a*a - x
if x < y:
break
else:
for c in range(int(math.sqrt(x)), a):
z = c*c - x
if z > y:
break
else:
if all([is_sq(x - z), is_sq(y + z), is_sq(y - z)]):
return x + y + z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment