Skip to content

Instantly share code, notes, and snippets.

@evansneath
Created August 20, 2011 22:56
Show Gist options
  • Select an option

  • Save evansneath/1159789 to your computer and use it in GitHub Desktop.

Select an option

Save evansneath/1159789 to your computer and use it in GitHub Desktop.

Revisions

  1. evansneath revised this gist Aug 20, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pythagorean_triples.py
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,6 @@ def pythagorean_triples(n):
    while (b < n // 2):
    c = n - a - b
    if (a**2 + b**2 == c**2):
    return(a, b, c)
    return a, b, c
    b = b + 1
    a, b = a + 1, 1
  2. evansneath created this gist Aug 20, 2011.
    16 changes: 16 additions & 0 deletions pythagorean_triples.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    def pythagorean_triples(n):
    """Finds a, b, and c such that a + b + c = n and a^2 + b^2 = c^2.
    Arguments:
    n: Value from which to determine pythagorean triples.
    Returns:
    Resulting combination of a, b, and c to satisfy the formula.
    """
    a, b = 1, 1
    while (a < n // 2):
    while (b < n // 2):
    c = n - a - b
    if (a**2 + b**2 == c**2):
    return(a, b, c)
    b = b + 1
    a, b = a + 1, 1