Skip to content

Instantly share code, notes, and snippets.

@mylesmegyesi
Created November 22, 2011 16:43
Show Gist options
  • Save mylesmegyesi/1386142 to your computer and use it in GitHub Desktop.
Save mylesmegyesi/1386142 to your computer and use it in GitHub Desktop.
Prime Factors in Clojure
(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