Created
November 22, 2011 16:43
-
-
Save mylesmegyesi/1386142 to your computer and use it in GitHub Desktop.
Prime Factors in Clojure
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 prime-factors [n] | |
(loop [n n divisor 2 factors []] | |
(if (< n 2) | |
factors | |
(if (= 0 (rem n divisor)) | |
(recur (/ n divisor) divisor (conj factors divisor)) | |
(recur n (inc divisor) factors) | |
) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment