Skip to content

Instantly share code, notes, and snippets.

View whamtet's full-sized avatar

Matthew Molloy whamtet

View GitHub Profile
@whamtet
whamtet / primes.clj
Last active February 16, 2021 18:14
(defn next-prime
([] (concat [2 3] (next-prime [2 3])))
([primes]
(loop [candidate (-> primes peek (+ 2))]
(if (->> primes
(take-while #(<= % (Math/sqrt candidate)))
(some #(zero? (mod candidate %))))
(recur (+ candidate 2))
(lazy-seq (cons candidate (next-prime (conj primes candidate))))))))