forked from OmkarPathak/pygorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcm.py
More file actions
31 lines (24 loc) · 765 Bytes
/
Copy pathlcm.py
File metadata and controls
31 lines (24 loc) · 765 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
# Author : OMKAR PATHAK
# Created at: 16th August 2017
from functools import reduce # need this line if you're using Python3.x
def lcm(List):
''' function to find LCM for given list of elements
:param List: List of which LCM is to be found out
'''
def _lcm(a, b):
''' helper function for finding LCM '''
if a > b:
greater = a
else:
greater = b
while True:
if greater % a == 0 and greater % b == 0:
lcm = greater
break
greater += 1
return lcm
return reduce(lambda x, y: _lcm(x, y), List)
def get_code():
""" returns the code for the current class """
import inspect
return inspect.getsource(lcm)