Last active
February 19, 2019 16:03
-
-
Save jreighley/74d6c3a3ac482edeea1ace3f534d7bf3 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes -- Clojure
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 filter-factors [primes unfiltered] | |
(let [new-prime (first unfiltered) | |
new-primes (conj primes new-prime) | |
new-unfiltered (filter #(< 0 (mod % new-prime)) unfiltered)] | |
(if (zero? (count new-unfiltered)) | |
new-primes | |
(recur new-primes new-unfiltered)))) | |
(defn soe [n] | |
(filter-factors [] (range 2 (inc n)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment