Skip to content

Instantly share code, notes, and snippets.

@mowen
Created April 3, 2010 20:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
(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