Created
February 24, 2021 21:19
-
-
Save stuartstein777/c33b8468e40a6f4e44d967a7c28ae832 to your computer and use it in GitHub Desktop.
sieve of erastothanes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; slow :( | |
(defn sieve-primes [upper] | |
(let [xs (->> (range 1 (inc upper)) | |
(set))] | |
(sort (reduce #(if (or (= 1 %2) (not (%1 %2))) | |
%1 | |
(let [multiples (range (* 2 %2) (inc upper) %2)] | |
(set/difference %1 multiples))) xs (range 1 (Math/sqrt (inc upper))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment