Skip to content

Instantly share code, notes, and snippets.

@craftybones
Last active June 12, 2016 08:03
Show Gist options
  • Save craftybones/35cf1c3f5dab8037d030fda30c8ee194 to your computer and use it in GitHub Desktop.
Save craftybones/35cf1c3f5dab8037d030fda30c8ee194 to your computer and use it in GitHub Desktop.
(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