Skip to content

Instantly share code, notes, and snippets.

@slagyr
Created May 11, 2011 19:39
Show Gist options
  • Save slagyr/967161 to your computer and use it in GitHub Desktop.
Save slagyr/967161 to your computer and use it in GitHub Desktop.
Prime Factors in Clojure
(ns prime-factors)
(defn factors-of [n]
(loop [factors [] divisor 2 n n]
(if (<= n 1)
factors
(if (= 0 (rem n divisor))
(recur
(conj factors divisor)
divisor
(/ n divisor))
(recur
factors
(inc divisor)
n)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment