Skip to content

Instantly share code, notes, and snippets.

@nbeloglazov
Created February 7, 2010 12:58
Show Gist options
  • Save nbeloglazov/297421 to your computer and use it in GitHub Desktop.
Save nbeloglazov/297421 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))))
(def primes (lazy-cat [2 3]
(filter #(prime? % primes)
(range 5 100))))
primes
;; -> 2 3 5 7 11 13 17 19 23 25 29 31 35 37 41 43 47 53 59 61 67 71 73 79 83 89 97 but 25 and 35 aren't primes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment