Created
April 19, 2011 01:54
-
-
Save mecdemort/926654 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;; clojure.contrib.lazy-seqs/primes | |
(defn primes | |
([] (cons 2 (primes [2] 3))) | |
([ps n] | |
(lazy-seq | |
(if (not-any? #(zero? (rem n %)) (take-while #(<= (* % %) n) ps)) | |
(cons n (primes (conj ps n) (+ 2 n))) | |
(primes ps (+ 2 n)))))) | |
(def primes | |
(cons 2 | |
((fn primesfn [n] | |
(lazy-seq | |
(if (some #(zero? (rem n %)) (take-while #(<= (* % %) n) primes)) | |
(primesfn (+ 2 n)) | |
(cons n (primesfn (+ 2 n)))))) | |
3))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment