Skip to content

Instantly share code, notes, and snippets.

@mowen
Created April 3, 2010 20:21
Show Gist options
  • Save mowen/354826 to your computer and use it in GitHub Desktop.
Save mowen/354826 to your computer and use it in GitHub Desktop.
(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