Skip to content

Instantly share code, notes, and snippets.

@igorvanloo
Created December 11, 2021 11:22
Show Gist options
  • Save igorvanloo/c5683c40e83c1586e8e7b9c6edbac1f6 to your computer and use it in GitHub Desktop.
Save igorvanloo/c5683c40e83c1586e8e7b9c6edbac1f6 to your computer and use it in GitHub Desktop.
LCM Function
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