Last active
June 12, 2016 08:03
-
-
Save craftybones/35cf1c3f5dab8037d030fda30c8ee194 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 prime-candidates | |
([] (lazy-seq (list* 2 3 (prime-candidates 1)))) | |
([x] (lazy-seq (list* (dec (* x 6)) (inc (* x 6)) (prime-candidates (inc x)))))) | |
(defn prime-candidates-less-than | |
[threshold] | |
(take-while (partial >= threshold) (prime-candidates))) | |
(defn is-prime? | |
[x] | |
(let [threshold (closest-integer-sqrt x) | |
x-divisible-by? (partial can-divide? x)] | |
(none x-divisible-by? (prime-candidates-less-than threshold)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment