Last active
August 29, 2015 14:14
-
-
Save krishnabhargav/da6686e295638d000aab to your computer and use it in GitHub Desktop.
GCD/LCM in F#
This file contains hidden or 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
let rec gcd a b = match (a,b) with | |
| (x,y) when x = y -> x | |
| (x,y) when x > y -> gcd (x-y) y | |
| (x,y) -> gcd x (y-x) | |
let lcm a b = a*b/(gcd a b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
let rec gcd a b = match (a,b) with
| (x,0) -> x
| (0, y) -> y
| (a,b) -> gcd b (a % b)