Skip to content

Instantly share code, notes, and snippets.

@w-k-s
Last active July 23, 2017 19:22
Show Gist options
  • Save w-k-s/8f130e3e7296c2fc76851f5f908c3f41 to your computer and use it in GitHub Desktop.
Save w-k-s/8f130e3e7296c2fc76851f5f908c3f41 to your computer and use it in GitHub Desktop.
Greatest Common Denominator
;tutorial: http://www.braveclojure.com/do-things/
(defn gcd
[a b]
(loop [dividend (max a b), divisor (min a b)]
(def remainder (rem dividend divisor))
(if (= remainder 0)
divisor
(recur divisor remainder)))
)
(gcd 32 5);1
(gcd 48 18);6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment