Sha256: 1abbbad52f6fbbf8b05d5d7ffd6610810d4c518ed7ea7a953d2692b98b3fa18b

Contents?: true

Size: 684 Bytes

Versions: 396

Compression:

Stored size: 684 Bytes

Contents

(ns sieve)

(defn sieve
  "Returns a list of primes less than or equal to limit"
  [limit]
  (loop [current-sieve (concat [false false] (range 2 (inc limit)))
         last-prime 1]
    (let [current-prime (->> current-sieve
                             (drop (inc last-prime))
                             (some identity))]
      (if current-prime
        (recur (map #(and %1 %2)
                    (concat (repeat (inc current-prime) true)
                            (cycle (concat (repeat (dec current-prime) true)
                                           [false])))
                    current-sieve)
               current-prime)
        (filter identity current-sieve)))))

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.179 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.178 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.177 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.176 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.175 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.174 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.173 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.172 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.171 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.170 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.169 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.167 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.166 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.165 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.164 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.163 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.162 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.161 tracks/clojure/exercises/sieve/src/example.clj
trackler-2.2.1.160 tracks/clojure/exercises/sieve/src/example.clj