Prime factorization in clojure.
This commit is contained in:
parent
11b5c8d5ca
commit
aece5b5da4
1 changed files with 13 additions and 0 deletions
13
primefactors.clj
Normal file
13
primefactors.clj
Normal file
|
@ -0,0 +1,13 @@
|
|||
(defn factors [x]
|
||||
(if (== x 1)
|
||||
'()
|
||||
(let [f
|
||||
(first
|
||||
(filter (fn [e] (zero? (mod x e)))
|
||||
(range 2 (+ x 1))
|
||||
)
|
||||
)]
|
||||
(conj (factors (/ x f)) f)
|
||||
)
|
||||
)
|
||||
)
|
Loading…
Reference in a new issue