Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
coding-dojo-20110921
(defn primes []
((fn primes [candidate seen]
(lazy-seq
(letfn [(prime? [candidate] (when-not (some #(zero? (rem candidate %)) seen) candidate))]
(when-let [candidate (some prime? (iterate inc candidate))]
(cons candidate (primes (inc candidate) (cons candidate seen)))))))
2 ()))
(fact
(primes 1) => (2)
(primes 2) => (2 3)
(primes 3) => (2 3 5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.