**Difference between sum of squares and square of sums**

Find the difference between the sum of squares and the square of the sum of the integers 1 to 100

Using the functions *map* and *reduce*, this becomes trivial to implement

(defn sqr [x]
(* x x))
(let [terms (range 1 101)]
(- (reduce + (map sqr terms)) (sqr (reduce + terms))))

*map* takes a function and 1 or more lists and generates a new list of terms which are a result of the application of the function on each of the terms in the list/lists

(map + '(1 2 3) '(1 2 3))
=> (2 4 6)

### Like this:

Like Loading...

*Related*

## Leave a Reply