Skip to content

Instantly share code, notes, and snippets.

@kiras
Created June 26, 2010 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiras/454257 to your computer and use it in GitHub Desktop.
Save kiras/454257 to your computer and use it in GitHub Desktop.
;; 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
@drcabana
Copy link

;; saw you were asking about this on clojure-log, here's my take
(->> (range 1000)
(filter #(or (zero? (mod % 3))
(zero? (mod % 5)))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment