Last active
April 21, 2020 23:22
-
-
Save arthuralvim/828cd8b834f0af08108f6990c0db61a6 to your computer and use it in GitHub Desktop.
Basic Math Utils
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
from math import gcd | |
from functools import reduce | |
# or | |
# def gcd(a, b): | |
# """Return greatest common divisor using Euclid's Algorithm.""" | |
# while b: | |
# a, b = b, a % b | |
# return a | |
def lcm(a, b): | |
"""Return lowest common multiple.""" | |
return a * b // gcd(a, b) | |
def lcmm(numbers): | |
"""Return lcm of numbers.""" | |
return reduce(lcm, numbers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment