one-file-projects/primesfactors.clj

15 lines
393 B
Clojure
Raw Permalink Normal View History

(defn prime-factors [n]
(loop [nums (cons 2 (iterate #(+ 2 %) 3))
factors []
v n]
(let [f (first nums)]
(cond
(= v 1) factors
(= 0 (mod v f)) (recur nums (conj factors f) (quot v f))
:else (recur (rest nums) factors v)))))
;(loop [i 1]
; (when (< i 100)
; (println i (prime-factors i))
; (recur (inc i))))
(println 123 (prime-factors 123))