Clojure - tail recursive sieve of Eratosthenes

后端 未结 3 2006
说谎
说谎 2021-01-11 21:53

I have this implementation of the sieve of Eratosthenes in Clojure:

(defn sieve [n]
  (loop [last-tried 2 sift (range 2 (inc n))]
    (if
      (or (nil? las         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-11 22:11

    I second Michal Marczyk's comment about checking out cgrande's beautiful incremental SoE. I did some really primitive benchmarks and put them up at http://clojure.roboloco.net/?p=100, for those curious about lazy prime generator performance.

提交回复
热议问题