one-file-projects/primesfactors.clj
Valentin Gehrke b8b6518057 3 more files
Signed-off-by: Valentin Gehrke <madmaurice@zom.bi>
2016-11-09 02:02:03 +01:00

14 lines
393 B
Clojure

(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))