Skip to content

Commit

Permalink
Calculate GCD using euclidean algo and lcm
Browse files Browse the repository at this point in the history
  • Loading branch information
Garvit244 committed Oct 3, 2017
1 parent 861e5e2 commit 715bc44
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
14 changes: 14 additions & 0 deletions algebra/gcd/python/gcd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
euclid_gcd(0 is used to find the gcd of two numbers using euclidean algorithm
@input: a, b numbers
@output gcd(a,b)
"""

def euclid_gcd(a, b):
if a < b:
return euclid_gcd(b, a)

while b != 0:
(a, b) = (b, a%b)

return a
23 changes: 23 additions & 0 deletions algebra/gcd/python/lcm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
euclid_gcd() is used to find the gcd of two numbers using euclidean algorithm
@input: a, b numbers
@output gcd(a,b)
"""

def euclid_gcd(a, b):
if a < b:
return euclid_gcd(b, a)

while b != 0:
(a, b) = (b, a%b)

return a
"""
lcm() is used to return the least common multiple between two numbers
@input: a, b numbers
@output: lcm(a, b)
"""

def lcm(a, b):
gcd = euclid_gcd(a, b)
return (a*b)/gcd

0 comments on commit 715bc44

Please sign in to comment.