This didn't take me nearly as long as my last example. Hurray for me!
;; Goal -- add all sums <=1000 that are divisible by 3 or 5 ;; with more than a little help from: ;; http://clojure.roboloco.net/?p=11 (ns squarepegsystems.naturalsums (:use clojure.test)) (defn divisible [ little big] (=(mod big little) 0) ) (defn multiple-3-or-5 [value] (or (divisible 5 value) (divisible 3 value) ) ) (deftest testdiv (is (= true (divisible 1 1))) (is (= true (divisible 1 1))) (is (= false (divisible 2 3))) (is (= true (divisible 2 4))) (is (= false (divisible 4 2))) ) (deftest testmultiple-3-or-5 (is (= true (multiple-3-or-5 5))) (is (= true (multiple-3-or-5 15))) (is (= true (multiple-3-or-5 3))) (is (= true (multiple-3-or-5 9))) ) (deftest testfilter (is(=() (filter #(divisible 5 %) [1 2 3 4]))) (is(= [10 15 20] (filter #(divisible 5 %) [10 15 20]))) ) ;(run-tests) (prn (reduce +(filter #(multiple-3-or-5 %) (range 1000))))