[Cs254f11] Prime Q
James Matheson
jmatheson12 at gmail.com
Mon Sep 26 15:59:01 EDT 2011
So here I have two (working) functions defining the factors (labeled
factorsA and factorsB) which seem to work exactly the same. However I
don't map factorsB. Can someone explain to me how map is working here?
(defn factorsB [n]
(filter #(integer? (/ n %)) (range 1 (+ n 1))))
(defn factorsA [n]
(map #(/ n %) (filter #(integer? (/ n %)) (range 1 (+ n 1)))))
(defn prime? [n]
(or (= n 2) (= 2 (count (take 3 (factorsB n))))))
(defn prime-factors [n]
(filter prime? (factorsB n)))
--Jamie
More information about the Cs254f11
mailing list