Skip to content

Instantly share code, notes, and snippets.

@arthuralvim
Last active April 21, 2020 23:22
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 arthuralvim/828cd8b834f0af08108f6990c0db61a6 to your computer and use it in GitHub Desktop.
Save arthuralvim/828cd8b834f0af08108f6990c0db61a6 to your computer and use it in GitHub Desktop.
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