Created
February 7, 2010 13:16
-
-
Save lypanov/297436 to your computer and use it in GitHub Desktop.
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 take-potential-divisors [p coll] | |
"Takes only those number from coll, whose square less or equal than p" | |
(take-while #(>= p (* % %)) coll)) | |
(defn prime? [p coll] | |
"Test whether p is prime or not. coll - prime numbers less than p" | |
(nil? (some #(zero? (rem p %)) (take-potential-divisors p coll)))) | |
(defn primes-seq [x] (lazy-cat | |
[2] (filter #(prime? % (primes-seq x)) (iterate inc x)))) | |
(def primes (primes-seq 3)) | |
(take 5 primes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment