I'd like to get the code below reviewed on all aspects, specifically I wonder if it's common usage to use let
like this, as currently more computations are done in the let
statement than in the rest of the code.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
problems/problem6.clj
(ns project-euler.problems.problem6
(:require [project-euler.shared :as shared]))
(defn sum-square-difference [n]
{:pre [(number? n)]}
(let [sum-squares (reduce + (map shared/square (range 1 (inc n))))
square-sum (shared/square (reduce + (range 1 (inc n))))]
(- square-sum sum-squares)))
(println (sum-square-difference 100))
shared.clj
(ns project-euler.shared
(:require [clojure.math.numeric-tower :as math]))
(defn square [n]
{:pre [(number? n)]}
(math/expt n 2))