You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sicp-all-tasks/sicp/4_002e37

17 lines
557 B

Exercise 4.37: Ben Bitdiddle claims that the
following method for generating Pythagorean triples is more efficient than the
one in Exercise 4.35. Is he correct? (Hint: Consider the number of
possibilities that must be explored.)
(define (a-pythagorean-triple-between low high)
(let ((i (an-integer-between low high))
(hsq (* high high)))
(let ((j (an-integer-between i high)))
(let ((ksq (+ (* i i) (* j j))))
(require (>= hsq ksq))
(let ((k (sqrt ksq)))
(require (integer? k))
(list i j k))))))