Created
April 29, 2012 11:46
-
-
Save ponkore/2549731 to your computer and use it in GitHub Desktop.
Project Euler Problem 10
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
;;; The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. | |
;;; Find the sum of all the primes below two million. | |
(defn primes [n] | |
(loop [prime-list '(2) search-list (take-while #(< % n) (iterate inc 2))] | |
(let [prime-list-max (first prime-list) | |
search-list-next (filter #(not (zero? (mod % prime-list-max))) search-list)] | |
(if (< n (* prime-list-max prime-list-max)) | |
(sort (concat prime-list search-list-next)) | |
(recur (conj prime-list (first search-list-next)) search-list-next))))) | |
(def primes-2m (primes (* 200 10000))) | |
(count primes-2m) | |
;;; => 148933 | |
(apply + primes-2m) | |
;;; => ans. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment