Skip to content

Instantly share code, notes, and snippets.

@sinemetu1
Created February 21, 2012 01:36
Show Gist options
  • Save sinemetu1/1872843 to your computer and use it in GitHub Desktop.
Save sinemetu1/1872843 to your computer and use it in GitHub Desktop.
Lazy-Primes
(defn lazy-seq-prime
([]
(concat [2] (lazy-seq-prime 2 (iterate inc 2))))
([p nums]
(let [nnums (filter (fn [x] (pos? (rem x p))) nums) n (first nnums)]
(lazy-seq
(cons n (lazy-seq-prime n nnums))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment