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
This commit is contained in:
parent
8bf4f1671c
commit
c8fcac1370
1 changed files with 15 additions and 0 deletions
15
primes.clj
Normal file
15
primes.clj
Normal file
|
@ -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)))))
|
Loading…
Reference in a new issue