Last active
December 7, 2016 20:20
-
-
Save emdeesee/4333778 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes
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 gen-primes [] | |
(letfn [(reinsert [table x prime] | |
(update-in table [(+ prime x)] conj prime)) | |
(step [table d] | |
(if-let [factors (table d)] | |
(recur (reduce #(reinsert %1 d %2) (dissoc table d) factors) | |
(inc d)) | |
(lazy-seq (cons d | |
(step (assoc table (* d d) (list d)) (inc d))))))] | |
(step {} 2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment