Hi, Can someone explain to me the behavior of this function when applied to different kind of numbers.
(defn prime-factors [n] (loop [f 2 n n res []] (cond (<= n 1) res (zero? (rem n f)) (recur f (quot n f) (conj res f)) :else (recur (inc f) n res)))) Problem 1 (solved): If you use (= n 1) in the first cond clause, the function may not terminate because (= 1 1.0) may be false. But we all know that :) Problem 2: Now compare theses function calls (prime-factors (Math/pow 2 58)) (prime-factors (bigdec (Math/pow 2 58))) (prime-factors (bigint (bigdec (Math/pow 2 58)))) The last two function calls are really really slow. - Is this only a problem of rem/quot slow on big numbers ? - Laurent -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en