-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem-006.lisp
More file actions
29 lines (22 loc) · 938 Bytes
/
problem-006.lisp
File metadata and controls
29 lines (22 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
;;;; Problem 6
(defun problem-006 ()
(sum-square-difference 100))
(defun sum-square-difference (num)
"Returns the difference of the square of the sum
of all the first num natural numbers, and the
sum of the squares of all the first num natural numbers."
(let* ((number-list (loop for i from 1 upto num
collecting i))
(sum-of-squares (reduce #'+
(mapcar #'square
number-list)))
(square-of-sum (square (apply #'+
number-list))))
(- square-of-sum
sum-of-squares)))
;; (PROBLEM-006)
;; took 15 microseconds (0.000015 seconds) to run.
;; During that period, and with 8 available CPU cores,
;; 15 microseconds (0.000015 seconds) were spent in user mode
;; 4 microseconds (0.000004 seconds) were spent in system mode
;; 3,216 bytes of memory allocated.