Created
April 3, 2010 21:10
-
-
Save mowen/354853 to your computer and use it in GitHub Desktop.
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 martin) | |
(defn evenly-divisible? | |
"Is N evenly-divisible by all of the numbers in SEQ?" | |
[n seq] | |
(loop [s seq] | |
;; TODO: Find out how to do 'cond' in Clojure | |
(if (empty? s) | |
true | |
(if (not (zero? (mod n (first s)))) | |
false | |
(recur (rest s)))))) | |
(defn euler-5 | |
"What is the smallest number that is evenly divisible by all of the numbers | |
from 1 to 20?" | |
[limit] | |
(let [nums (range 1 (+ 1 limit))] | |
(loop [n 20] | |
(if (evenly-divisible? n nums) | |
n | |
(recur (inc n)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment