Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Basic Math Utils
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