This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn prime? [n] | |
(loop [n n prime 2 factors []] | |
(if (> (count factors) 1) | |
false | |
(cond | |
(= n 1) true | |
(factor? n prime) (recur (/ n prime) prime (conj factors prime)) | |
:else (recur n (inc prime) factors))))) | |
(def nums (iterate inc 2)) | |
(last (take 10001 (filter prime? nums))) ; 104743 |
It works but it's quite slow.
No comments:
Post a Comment