Created
July 6, 2012 09:17
-
-
Save simlun/3059159 to your computer and use it in GitHub Desktop.
euler001
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
(ns euler001.euler) | |
(defn- zerorem? | |
[numer denom] | |
(= 0 (rem numer denom))) | |
(defn divis? | |
[a] | |
(or | |
(zerorem? a 3) | |
(zerorem? a 5))) | |
(defn multiplesum | |
[limit] | |
(reduce + (filter divis? (range 1 limit)))) |
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
(ns euler001.euler-test | |
(:use midje.sweet | |
euler001.euler)) | |
(fact "multiplesum of 2 is 0" | |
(multiplesum 2) => 0) | |
(fact "multiplesum of 4 is 3" | |
(multiplesum 4) => 3) | |
(fact "divis? checks if arg is divisable by 3 or 5" | |
(divis? 2) => false | |
(divis? 3) => true | |
(divis? 4) => false | |
(divis? 5) => true | |
(divis? 6) => true | |
(divis? 7) => false) | |
(fact "10 => 23" | |
(multiplesum 10) => 23) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment