forked from OmkarPathak/pygorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcm_using_gcd.py
More file actions
37 lines (30 loc) · 705 Bytes
/
lcm_using_gcd.py
File metadata and controls
37 lines (30 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Author: Ashutosh Gupta
Created On: 8/17/2017
Time: 10:03 PM
"""
import inspect
def gcd(x, y):
"""
Function to find gcm (greatest common divisor) of two numbers
:param x: first number
:param y: second number
:return: gcd of x and y
"""
while y != 0:
(x, y) = (y, x % y)
return x
def lcm_using_gcd(_list):
"""
function to find LCM for given list of elements
:param _list: _list of which LCM is to be found out
"""
lcm = _list[0]
for element in _list:
lcm = lcm * element / gcd(lcm, element)
return lcm
def get_code():
"""
returns the code for the gcd function
"""
return inspect.getsource(lcm_using_gcd)