summaryrefslogtreecommitdiff
path: root/lecture_notes/test_driven_development/math_utils/gcd.py
diff options
context:
space:
mode:
Diffstat (limited to 'lecture_notes/test_driven_development/math_utils/gcd.py')
-rw-r--r--lecture_notes/test_driven_development/math_utils/gcd.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/lecture_notes/test_driven_development/math_utils/gcd.py b/lecture_notes/test_driven_development/math_utils/gcd.py
new file mode 100644
index 0000000..7204ac0
--- /dev/null
+++ b/lecture_notes/test_driven_development/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()