Created
December 11, 2021 11:22
-
-
Save igorvanloo/c5683c40e83c1586e8e7b9c6edbac1f6 to your computer and use it in GitHub Desktop.
LCM Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lcm(numbers): | |
n = sorted(numbers) #I want to start with the largest numbers | |
curr = n.pop(-1) #Remove the biggest | |
while len(n) != 0: | |
temp = n.pop(-1) | |
curr = int(abs(curr*temp)/math.gcd(curr, temp)) #Continuously find the lcm between the 2 largest numbers | |
return curr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment