Skip to content

Instantly share code, notes, and snippets.

@simlun

simlun/euler.clj

Created Jul 6, 2012
Embed
What would you like to do?
euler001
(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))))
(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