Last active
July 13, 2018 21:54
-
-
Save khaledsaikat/08228454b21d3360bf5e882d18a37fef to your computer and use it in GitHub Desktop.
GCD and LCM in python for list
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
#!/usr/bin/env python3 | |
from math import gcd | |
from functools import reduce | |
def lcm(a, b): | |
"""lowest common multiple of a and b""" | |
return int(a * b / gcd(a, b)) | |
def gcd_from_list(arr): | |
"""Calculate greatest common divisor from list""" | |
return reduce(gcd, arr) | |
def lcm_from_list(arr): | |
"""Calculate lowest common multiple from list""" | |
return reduce(lcm, arr) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment