Created
April 3, 2010 20:21
-
-
Save mowen/354826 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 sqr | |
"Square the given number." | |
[n] | |
(. (BigInteger/valueOf n) (pow 2))) | |
(defn euler-6 | |
"Find the difference between the sum of the squares of the first one hundred | |
natural numbers and the square of the sum." | |
[limit] | |
(let [nums (range 1 (+ 1 limit)) | |
sum-of-squares (reduce + (map #(sqr %) nums)) | |
square-of-sum (sqr (reduce + nums))] | |
(- square-of-sum sum-of-squares))) | |
(euler-6 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment