Open the context
Choose the project folder and name the files or behavior involved.
Enumerate primitive integer right triangles whose hypotenuse is at most a supplied limit from zero through 500. Check the empty result and 3-4-5, exclude scaled copies and return each leg-ordered triple once.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
from math import gcd
def primitive_triples(limit):
if type(limit) is not int or not 0 <= limit <= 500:
raise ValueError("hypotenuse.limit")
result, m = [], 2
while m * m + 1 <= limit:
for n in range(1, m):
c = m * m + n * n
if c <= limit and (m - n) % 2 and gcd(m, n) == 1:
a, b = sorted((m * m - n * n, 2 * m * n))
result.append((a, b, c))
m += 1
return sorted(result, key=lambda t: (t[2], t[0], t[1]))The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.