Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisvest/956746 to your computer and use it in GitHub Desktop.
Save chrisvest/956746 to your computer and use it in GitHub Desktop.
;; 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