Skip to content

Instantly share code, notes, and snippets.

@mowen
Created April 3, 2010 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mowen/354853 to your computer and use it in GitHub Desktop.
Save mowen/354853 to your computer and use it in GitHub Desktop.
(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