Skip to content

Instantly share code, notes, and snippets.

@iandesj
Last active October 23, 2019 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iandesj/079784c50bd00ce34ed27117f03b2970 to your computer and use it in GitHub Desktop.
Save iandesj/079784c50bd00ce34ed27117f03b2970 to your computer and use it in GitHub Desktop.
Least common multiple finder i wrote in python... cuz who doesn't need a good LCM finder from time to time, amirite?
def lcm(nums):
greatest = max(nums)
while True:
all_good = all(
list(map(lambda x: greatest % x == 0, nums))
)
if all_good:
return greatest
greatest += 1
# usage examples
print(lcm([25, 10, 1]))
# => 50
print(lcm([15, 3, 1]))
# => 15
print(lcm([16, 36]))
# => 144
print(lcm([18, 36]))
# => 36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment