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
42 lines (34 loc) · 806 Bytes
/
lcm.py
File metadata and controls
42 lines (34 loc) · 806 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
38
39
40
41
42
"""
Author: OMKAR PATHAK
Created at: 16th August 2017
"""
from functools import reduce
import inspect
def lcm(_list):
"""LCM
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
:param a:
:param b:
:return: 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 lcm function
"""
return inspect.getsource(lcm)