Skip to content

Instantly share code, notes, and snippets.

@krishnabhargav
Last active August 29, 2015 14:14
Show Gist options
  • Save krishnabhargav/da6686e295638d000aab to your computer and use it in GitHub Desktop.
Save krishnabhargav/da6686e295638d000aab to your computer and use it in GitHub Desktop.
GCD/LCM in F#
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)
@krishnabhargav
Copy link
Author

let rec gcd a b = match (a,b) with
| (x,0) -> x
| (0, y) -> y
| (a,b) -> gcd b (a % b)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment