diff options
Diffstat (limited to 'lecture-notes/tdd/math_utils/gcd.py')
-rw-r--r-- | lecture-notes/tdd/math_utils/gcd.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lecture-notes/tdd/math_utils/gcd.py b/lecture-notes/tdd/math_utils/gcd.py new file mode 100644 index 0000000..7204ac0 --- /dev/null +++ b/lecture-notes/tdd/math_utils/gcd.py @@ -0,0 +1,22 @@ +def gcd(a, b): + """Returns the Greatest Common Divisor of the two integers + passed as arguments. + + Args: + a: an integer + b: another integer + + Returns: Greatest Common Divisor of a and b + + >>> gcd(48, 64) + 16 + >>> gcd(44, 19) + 1 + """ + if b == 0: + return b + return gcd(b, a%b) + +if __name__ == "__main__": + import doctest + doctest.testmod() |