Created
October 30, 2013 15:57
-
-
Save podviaznikov/7235142 to your computer and use it in GitHub Desktop.
The greatest common divisor (GCD) of two integers: x and y. http://people.cis.ksu.edu/~schmidt/301s12/Exercises/euclid_alg.html.
Clojure implementation.
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
(defn gdc [x y] | |
(if (= x y) | |
x | |
(if (> x y) | |
(recur (- x y) y) | |
(recur (- y x) x)))) | |
(gdc 10, 100) ; 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment