Skip to content

Instantly share code, notes, and snippets.

@borkdude
Created June 5, 2010 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borkdude/426665 to your computer and use it in GitHub Desktop.
Save borkdude/426665 to your computer and use it in GitHub Desktop.
(defn siever2 [to-sieve sieved end]
(if (empty? to-sieve) sieved
(let [f (first to-sieve)
r (rest to-sieve)]
(if (> f (Math/sqrt end))
(into sieved to-sieve)
(siever2 (remove #(zero? (mod % f)) r)
(conj sieved f)
end)))))
(dotrace [siever2] (siever2 (range 2 32) [] 31))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment