Last active
October 23, 2019 03:13
-
-
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?
This file contains 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(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