Skip to content

Instantly share code, notes, and snippets.

@gallettilance
Last active November 14, 2017 21:43
Show Gist options
  • Save gallettilance/c9228f0a0d95446f689ddaa793285cff to your computer and use it in GitHub Desktop.
Save gallettilance/c9228f0a0d95446f689ddaa793285cff to your computer and use it in GitHub Desktop.
Sieve Of Eratosthenes - Stream of Primes
(defn theNats [init]
(lazy-seq (cons (+ init 1) (theNats (+ init 1))))
)
(defn sieve [nats]
(lazy-seq (cons (first nats) (filter (fn [x] (> (mod x (first nats)) 0)) (rest nats)))
))
(def thePrimes (sieve (theNats 2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment