summaryrefslogtreecommitdiff
path: root/AlgoDesignAndTechniqueEdxPython/sources
diff options
context:
space:
mode:
authorHaidong Ji2018-08-19 16:50:35 -0500
committerHaidong Ji2018-08-19 16:50:35 -0500
commit79cc9a835416965720e923fac4a8c53c22108e73 (patch)
tree7979fc69d6cc02882367d1393a178173868cfbe9 /AlgoDesignAndTechniqueEdxPython/sources
parentb7a6d9d18945e81ba9c23cf90b41328e20ba1341 (diff)
Great LCM exercise. Done!
2 things are really interesting: 1. How to find the right test cases. I think I'll probably need to go back and re-read how to do an exhautisive testing 2. Python 3's floor division versus true division (// and /) operators are interesting. This exercise discussion helped me: https://courses.edx.org/courses/course-v1:UCSanDiegoX+ALGS200x+2T2017/discussion/forum/course/threads/5a3d32d644a15008df00062e and this one: https://stackoverflow.com/questions/19507808/python3-integer-division and this one: https://www.python.org/dev/peps/pep-0238/
Diffstat (limited to 'AlgoDesignAndTechniqueEdxPython/sources')
-rw-r--r--AlgoDesignAndTechniqueEdxPython/sources/gcdlcm.py (renamed from AlgoDesignAndTechniqueEdxPython/sources/gcd.py)5
1 files changed, 4 insertions, 1 deletions
diff --git a/AlgoDesignAndTechniqueEdxPython/sources/gcd.py b/AlgoDesignAndTechniqueEdxPython/sources/gcdlcm.py
index 7b107cd..57b48ff 100644
--- a/AlgoDesignAndTechniqueEdxPython/sources/gcd.py
+++ b/AlgoDesignAndTechniqueEdxPython/sources/gcdlcm.py
@@ -10,10 +10,13 @@ def getGCD(a, b):
else:
return getGCD(b, a % b)
+def getLCM(a, b):
+# https://www.idomaths.com/hcflcm.php#formula
+ return a * b // getGCD(a, b)
if __name__ == '__main__':
entryNumbers = sys.stdin.read()
tokens = entryNumbers.split()
a = int(tokens[0])
b = int(tokens[1])
- print(getGCD(a, b))
+ print(getLCM(a, b)) \ No newline at end of file