Skip to content

Instantly share code, notes, and snippets.

@mildsunrise
Last active January 14, 2018 16:00
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 mildsunrise/1753043 to your computer and use it in GitHub Desktop.
Save mildsunrise/1753043 to your computer and use it in GitHub Desktop.
Greatest Common Divisor (GCD), simplified
gcd = (a,b) -> if b then gcd b, a%b else a
mcm = (a,b) -> a*b / gcd(a,b)
def gcd(a,b) {
if (!b) a
else gcd(b, a%b)
}
def mcm(a,b) {
a*b / gcd(a,b)
}
def gcd(a,b):
if b==0: return a
return gcd(b, a%b)
def mcm(a,b):
return a*b / gcd(a,b)
def gcd(a,b)
if b==0: a
else gcd(b, a%b)
end
end
def mcm(a,b)
a*b / gcd(a,b)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment