Created
January 11, 2012 06:25
-
-
Save wjlafrance/1593355 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 pfilter [pred coll] | |
"perform filter in parallel" | |
(map second | |
(filter first | |
(pmap (fn [item] [(pred item) item]) coll) | |
) | |
) | |
) | |
(defn is-divisible [x y] | |
"determine if x / y is an integer" | |
(= | |
(/ (float x) (float y)) | |
(float (int (/ (float x) (float y)))) | |
) | |
) | |
(defn is-prime [x] | |
"determine if a number is prime" | |
(with-local-vars [value true y (- x 1)] | |
(while (> (var-get y) 1) | |
(if (is-divisible x (var-get y)) | |
(var-set value false) | |
) | |
(var-set y (- (var-get y) 1)) | |
) | |
(not (not (var-get value))) | |
) | |
) | |
(defn main [] | |
(println (pfilter is-prime (range 1 100000 1))) | |
(shutdown-agents) | |
) | |
(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment