From c8fcac13702102b700c500130c169fcf06e4fefa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pelletier?= Date: Sun, 27 Jul 2014 12:08:17 -0400 Subject: [PATCH] creation of file primes.clj This is a reimplementation with few minor corrections from clojure.contrib.lazy-seqs function primes. From defvar to def, with description as second argument --- primes.clj | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 primes.clj diff --git a/primes.clj b/primes.clj new file mode 100644 index 0000000..5f59e33 --- /dev/null +++ b/primes.clj @@ -0,0 +1,15 @@ +(def primes + "Lazy sequence of all the prime numbers." + (concat + [2 3 5 7] + (lazy-seq + (let [primes-from +(fn primes-from [n [f & r]] +(if (some #(zero? (rem n %)) +(take-while #(<= (* % %) n) primes)) +(recur (+ n f) r) +(lazy-seq (cons n (primes-from (+ n f) r))))) +wheel (cycle [2 4 2 4 6 2 6 4 2 4 6 6 2 6 4 2 +6 4 6 8 4 2 4 2 4 8 6 4 6 2 4 6 +2 6 6 4 2 4 6 2 6 4 2 4 2 10 2 10])] + (primes-from 11 wheel)))))