Created
July 29, 2016 22:53
-
-
Save zipcode/c6bfe71726bedda4431f8cb8e95470bd to your computer and use it in GitHub Desktop.
corecursive infinite list of primes in clojure
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 divides? | |
[x y] | |
(and (= 0 (mod x y)) (not (= x y)))) | |
(def primes | |
(lazy-cat | |
[2 3] | |
(filter | |
(fn [x] | |
(not (some | |
#(divides? x %) | |
(take-while | |
#(<= % (Math/ceil (Math/sqrt x))) | |
primes)))) | |
(iterate inc 5)))) | |
(defn prime? [x] | |
(not (some | |
#(divides? x %) | |
(take-while | |
#(<= % (Math/ceil (Math/sqrt x))) | |
primes)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment