-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem-009.lisp
More file actions
30 lines (24 loc) · 930 Bytes
/
Copy pathproblem-009.lisp
File metadata and controls
30 lines (24 loc) · 930 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
30
;;;; Problem #9 #9 #9
(defun problem-009 ()
"Returns the product of abc for pythagorean triplet."
(reduce #'*
(pythagorean-triplet 1000)))
(defun pythagorean-triplet (sum)
"Returns a special pythagorean triplet where a + b + c = sum."
(let ((answer nil))
(loop for a from 1 upto (/ sum 3)
do (loop for b from 1 upto (/ sum 2)
do (let ((c (- sum a b)))
(when
(= (square c)
(+ (square a)
(square b)))
(setf answer
(list a b c))))))
answer))
;; (PROBLEM-009)
;; took 3,808 microseconds (0.003808 seconds) to run.
;; During that period, and with 8 available CPU cores,
;; 3,795 microseconds (0.003795 seconds) were spent in user mode
;; 19 microseconds (0.000019 seconds) were spent in system mode
;; 80 bytes of memory allocated.