Module grscheller.boring_math.cli.pythag3

Entry point for the pythag3 cli script.

Expand source code
# Copyright 2023-2024 Geoffrey R. Scheller
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Entry point for the pythag3 cli script."""

from __future__ import annotations

__all__ = ['pythag3_cli']
__author__ = "Geoffrey R. Scheller"
__copyright__ = "Copyright (c) 2023-2024 Geoffrey R. Scheller"
__license__ = "Apache License 2.0"

import sys
from grscheller.boring_math.pythag3 import Pythag3

def pythag3_cli() -> None:
    """Prints tuples of primative pythagorian triples.

    * *Pythagorian* triple are `3` integers `a, b, c` where `a**2 + b**2 = c**2`
    * such a triple is primative when `a, b, c > 0` and `gcd(a, b, c) = 1`
    * geometrically `a, b, c` represent the sides of a right triangle

    Usage: pythag3.py [m [n [max]]]

    | # of args |     | Prints all possible triples `(a, b, c)` satisfying  |
    |:---------:| --- |:--------------------------------------------------- |
    |    `3`    |     | `m <= a <= n` and `a,b,c <= max`                    |
    |    `2`    |     | `m <= a <= n`                                       |
    |    `1`    |     | `a <= m`                                            |
    |    `0`    |     | `3 <= a <= 100`                                     |
    """
    pythag3 = Pythag3()

    args = sys.argv[1:]

    if len(args) > 2:
        pythagTriples = pythag3.triples(a_start = int(args[0]),
                                          a_max = int(args[1]),
                                            max = int(args[2]))
    elif len(args) == 2:
        pythagTriples = pythag3.triples(a_start = int(args[0]),
                                          a_max = int(args[1]))
    elif leng(args) == 1:
        pythagTriples = pythag3.triples(a_start = 3, a_max = int(args[0]))
    else:
        pythagTriples = pythag3.triples(a_start = 3, a_max = 100)

    # Print out Pythagean Triples
    for triple in pythagTriples:
        print(triple)

Functions

def pythag3_cli() ‑> None

Prints tuples of primative pythagorian triples.

  • Pythagorian triple are 3 integers a, b, c where a**2 + b**2 = c**2
  • such a triple is primative when a, b, c > 0 and gcd(a, b, c) = 1
  • geometrically a, b, c represent the sides of a right triangle

Usage: pythag3.py [m [n [max]]]

# of args Prints all possible triples (a, b, c) satisfying
3 m <= a <= n and a,b,c <= max
2 m <= a <= n
1 a <= m
0 3 <= a <= 100
Expand source code
def pythag3_cli() -> None:
    """Prints tuples of primative pythagorian triples.

    * *Pythagorian* triple are `3` integers `a, b, c` where `a**2 + b**2 = c**2`
    * such a triple is primative when `a, b, c > 0` and `gcd(a, b, c) = 1`
    * geometrically `a, b, c` represent the sides of a right triangle

    Usage: pythag3.py [m [n [max]]]

    | # of args |     | Prints all possible triples `(a, b, c)` satisfying  |
    |:---------:| --- |:--------------------------------------------------- |
    |    `3`    |     | `m <= a <= n` and `a,b,c <= max`                    |
    |    `2`    |     | `m <= a <= n`                                       |
    |    `1`    |     | `a <= m`                                            |
    |    `0`    |     | `3 <= a <= 100`                                     |
    """
    pythag3 = Pythag3()

    args = sys.argv[1:]

    if len(args) > 2:
        pythagTriples = pythag3.triples(a_start = int(args[0]),
                                          a_max = int(args[1]),
                                            max = int(args[2]))
    elif len(args) == 2:
        pythagTriples = pythag3.triples(a_start = int(args[0]),
                                          a_max = int(args[1]))
    elif leng(args) == 1:
        pythagTriples = pythag3.triples(a_start = 3, a_max = int(args[0]))
    else:
        pythagTriples = pythag3.triples(a_start = 3, a_max = 100)

    # Print out Pythagean Triples
    for triple in pythagTriples:
        print(triple)