Hi,
As has been said, this is not SoE. But my take would be something along :
(reduce
(fn [primes number]
(if (some zero? (map (partial mod number) (take-while #(<= %
(Math/sqrt number)) primes)))
primes
(conj primes number)))
[2]
(take n (iterate inc 3)))
But I'm a noob, so it migth be the bilnd leading the blind ☺
Best Regards,
b.
On Wednesday, November 26, 2014 3:52:44 PM UTC+1, Chernyshev Alex wrote:
>
> (defn not-divisible-by?[num denum]
> (not (= (mod num denum) 0)))
>
> (defn div-nums [denum bound]
> (for [x (range 2 bound) :when (not-divisible-by? x denum)] x))
>
> (defn divisible? [coll denum]
> (empty? (filter #(and (not= denum %) (not(not-divisible-by? denum %)))
> coll)))
>
> (defn generate-primes
> "Sieve of Eratosthenes"
> [n]
> (let [src (div-nums 2 n)]
> (cons 2 (for [x src :when (divisible? src x)] x))))
>
>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.