Skip to content

Instantly share code, notes, and snippets.

@erasmas
Created January 12, 2014 20:07
Show Gist options
  • Save erasmas/8389734 to your computer and use it in GitHub Desktop.
Save erasmas/8389734 to your computer and use it in GitHub Desktop.
Greatest common divisor in Clojure
(defn gcd [a b]
(let [min (min a b)
max (max a b)
rem (mod max min)]
(if (zero? rem)
min
(recur min rem))))
(defn gcd2 [a b]
(let [quotient (/ a b)]
(if (ratio? quotient)
(numerator quotient)
quotient)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment