We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 96d03a6 commit 161a983Copy full SHA for 161a983
pygorithm/math/lcm.py
@@ -0,0 +1,31 @@
1
+# Author : OMKAR PATHAK
2
+# Created at: 16th August 2017
3
+
4
+from functools import reduce # need this line if you're using Python3.x
5
6
+def lcm(List):
7
+ ''' function to find LCM for given list of elements
8
9
+ :param List: List of which LCM is to be found out
10
+ '''
11
+ def _lcm(a, b):
12
+ ''' helper function for finding LCM '''
13
+ if a > b:
14
+ greater = a
15
+ else:
16
+ greater = b
17
18
+ while True:
19
+ if greater % a == 0 and greater % b == 0:
20
+ lcm = greater
21
+ break
22
+ greater += 1
23
24
+ return lcm
25
26
+ return reduce(lambda x, y: _lcm(x, y), List)
27
28
+def get_code():
29
+ """ returns the code for the current class """
30
+ import inspect
31
+ return inspect.getsource(lcm)
0 commit comments