Skip to content

Instantly share code, notes, and snippets.

@lypanov
Created February 7, 2010 13:16
Show Gist options
  • Save lypanov/297436 to your computer and use it in GitHub Desktop.
Save lypanov/297436 to your computer and use it in GitHub Desktop.
(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