Skip to content

Instantly share code, notes, and snippets.

@hyone
Created April 13, 2011 08:25
Show Gist options
  • Save hyone/917189 to your computer and use it in GitHub Desktop.
Save hyone/917189 to your computer and use it in GitHub Desktop.
Primes by sieve of Eratosthenes (lazy evalution)
(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