Created
August 4, 2017 13:04
-
-
Save rmuslimov/d69d358a11c612f27ea633a88a152c55 to your computer and use it in GitHub Desktop.
sum primes
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 prime? | |
[n] | |
(let [divides? #(zero? (mod n %)) | |
candidates (range 2 (inc (/ n 2)))] | |
(and (> n 1) (not-any? divides? candidates)))) | |
(defn sum-prime-numbers | |
[numbers] | |
(->> numbers | |
(filter prime?) | |
(apply +))) | |
(def example-s1 [1 4 5 13 15 17 20 3]) | |
(sum-prime-numbers example-s1) | |
(def example-s2 [3 5 7]) | |
(sum-prime-numbers example-s2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment