Created
June 4, 2009 19:22
-
-
Save jimweirich/123787 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 reject-multiples | |
"A function that rejects multiples of n." | |
[n] | |
(fn [x] (not (zero? (mod x n))))) | |
(defn primes | |
"An infinite sequence of prime numbers" | |
([] (primes (iterate inc 2))) | |
([seq] | |
(let [head (first seq)] | |
(lazy-seq | |
(cons head | |
(primes (filter (reject-multiples head) (rest seq))) ))))) | |
; Print the first prime > 1000 | |
(println (first (drop-while #(< % 1000) (primes)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment