Last active
August 29, 2015 14:06
-
-
Save tylerjohnst/4d4f81f5fb1aef6fc2f9 to your computer and use it in GitHub Desktop.
Project Euler #1
This file contains 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 problems.one) | |
(defn- multiple-of [num x] (zero? (mod x num))) | |
(defn- multiples-of-three-and-five [x] | |
(or (multiple-of 3 x) | |
(multiple-of 5 x))) | |
(defn- real-numbers-below [x] (range 1 x)) | |
(defn multiples-of-three-and-five-below [x] | |
(filter multiples-of-three-and-five (real-numbers-below x))) | |
(defn sum-of-multiples [x] | |
(reduce + (multiples-of-three-and-five-below x))) | |
(sum-of-multiples 10000) |
This file contains 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 problems.one-test | |
(:require [clojure.test :refer :all] | |
[problems.one :refer :all])) | |
(deftest multiples-of-n | |
(testing "below 10 the multiples should be 3 5 6 and 9" | |
(is (= (multiples-of-three-and-five-below 10), [3 5 6 9]))) | |
(testing "the sum of all multiples below 10 should be 23" | |
(is (= (sum-of-multiples 10), 23))) | |
; SPOILERS!!! | |
(testing "the sum of all multiples below 1000 should be something" | |
(is (= (sum-of-multiples 1000), 233168))) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment