Last active
February 16, 2021 18:14
-
-
Save whamtet/1c084d8f94a26e490f756b274b7f89dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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