pythag3

Pythagorean triples

Pythagorean triples are three integers a, b, c where + = . Such a triple is primitive when a, b, c > 0 and gcd(a, b, c) = 1. Geometrically, a, b, c represent the sides of a right triangle.

class boring_math.pythagorean_triples.pythag3.Pythag3(last_square: int = 500, /)

Pythagorean triple iteration class.

extend_squares(last_to_square: int, /) None

Extend the self.squares perfect square lookup table.

triples(a_start: int = 3, a_max: int = 3, abc_max: int | None = None) Iterator[tuple[int, int, int]]

Returns an iterator of all possible primitive Pythagorean triples.

Note

Returned Iterator iterates in tuples (a, b, c) in dictionary order.

If abc_max not given, returns all theoretically possible triples with a_start <= a <= a_max.

Never returns an infinite iterator.

Parameters:
  • a_start – Starting value for the smallest side a.

  • a_max – Maximum value for the smallest side a.

  • abc_max – Maximum value for any side.

Returns:

Iterator of Tuples (a, b, c) with a_start <= a <= a_max and 3 <= a < b < c <= abc_max