-
-
Save chrisvest/956746 to your computer and use it in GitHub Desktop.
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
;; chrisvest's solution to http://4clojure.com/problem/75 | |
(fn [x] (if (= x 1) 1 | |
(let [coprime (fn [y] (= 1 | |
(loop [dividend (max x y) ;; Euclid's GCD algorithm | |
divisor (min x y) | |
quotient (quot dividend divisor) | |
remainder (rem dividend divisor)] | |
(if (zero? remainder) | |
divisor | |
(recur divisor | |
remainder | |
(quot divisor remainder) | |
(rem divisor remainder))))))] | |
(->> (range x 0 -1) (filter coprime) count)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment