Created
April 13, 2011 08:25
-
-
Save hyone/917189 to your computer and use it in GitHub Desktop.
Primes by sieve of Eratosthenes (lazy evalution)
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 nums [] (iterate inc 2)) | |
(defn sieve [[p & xs]] | |
(remove #(= (rem % p) 0) xs)) | |
(defn primes [] | |
(map first (iterate sieve (nums)))) | |
;; user> (take 20 (primes)) | |
;; (2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment