Created
June 26, 2010 18:43
-
-
Save kiras/454257 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
;; Code to find all the multiples of 3 or 5 below 1000. | |
(defn divisible-by-n-list [min max n] | |
(if-not (zero? n) | |
(loop [x (* (floor (/ max n)) n) | |
l (set ())] | |
(if (> x min) | |
(recur (- x n) (cons x l)) | |
l)) | |
(println "Cannot divide by zero."))) | |
(reduce + (set (into (divisible-by-n-list 0 1000 3) (divisible-by-n-list 0 1000 5)))) | |
;; Result is 234168 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
;; saw you were asking about this on clojure-log, here's my take
(->> (range 1000)
(filter #(or (zero? (mod % 3))
(zero? (mod % 5)))))