4.3.1. Amb and Search
Exercise 4.35

Write a procedure an-integer-between

Write a procedure an-integer-between that returns an integer between two given bounds. This can be used to implement a procedure that finds Pythagorean triples, i.e., triples of integers (i, j, k) between the given bounds such that i ≤ j and i² + j² = k², as follows:

(define (a-pythagorean-triple-between low high)
  (let ((i (an-integer-between low high)))
    (let ((j (an-integer-between i high)))
      (let ((k (an-integer-between j high)))
        (require (= (+ (* i i) (* j j)) (* k k)))
        (list i j k)))))

Nobody's finished this exercise yet. You'll be the first!

There are no comments yet.

Authentication required

You must log in to post a comment.