Last active
January 14, 2018 16:00
-
-
Save mildsunrise/1753043 to your computer and use it in GitHub Desktop.
Greatest Common Divisor (GCD), simplified
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
gcd = (a,b) -> if b then gcd b, a%b else a | |
mcm = (a,b) -> a*b / gcd(a,b) |
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
def gcd(a,b) { | |
if (!b) a | |
else gcd(b, a%b) | |
} | |
def mcm(a,b) { | |
a*b / gcd(a,b) | |
} |
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
def gcd(a,b): | |
if b==0: return a | |
return gcd(b, a%b) | |
def mcm(a,b): | |
return a*b / gcd(a,b) |
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
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