Clojure Prime Factors

Clojure Prime Factors

Posted by Uncle Bob on Saturday, May 15, 2010

Can anyone create a simpler version of prime factors in Clojure?

(ns primeFactors)  (defn of   ([n]     (of [] n 2))   ([factors n candidate]     (cond       (= n 1) factors       (= 0 (rem n candidate)) (recur (conj factors candidate) (quot n candidate) candidate)       (> candidate (Math/sqrt n)) (conj factors n)       :else (recur factors n (inc candidate))       )     )   )

Comments

Leave a response