Skip to content

Instantly share code, notes, and snippets.

@whamtet
Last active February 16, 2021 18:14
Show Gist options
  • Save whamtet/1c084d8f94a26e490f756b274b7f89dd to your computer and use it in GitHub Desktop.
Save whamtet/1c084d8f94a26e490f756b274b7f89dd to your computer and use it in GitHub Desktop.
(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))))))))
(->> (next-prime)
(take-while #(<= % 100))
prn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment