I've transformed algorithm to this:

(defn primes-bellow
        "calculates all primes bellow max"
        [max]
        (loop [numbers (vec (range 2 max)) primes [] last-p 0]
                (let [p (first (drop-while zero? (drop (dec last-p) numbers)))]
                        (if (> p (. Math sqrt max))
                                (concat primes (filter pos? numbers))
                                (let [numbers (reduce #(assoc %1 %2 0)
                                                                numbers
                                                                (range (- p 2) 
max p))
                                       primes (conj primes p)]
                                    (recur numbers primes p))))))

And I think, that this is real SoE, and it can calculate sum of first
2000000 prime numbers in ~35 sec, on 1.4 Celeron M.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to