TTripleMistral
Workflows

Coding workflows · Primitive Pythagorean triples

03
Built around your work

A concrete starting point

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.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Primitive Pythagorean triples

A concrete starting point
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.

AI coding workspace

Your next change starts here.

Get the Windows app ↗