sicp-ex-4.36



<< Previous exercise (4.35) | Index | Next exercise (4.37) >>


meteorgan

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

squeegie

  
  
  
 ;shorter, but very inefficient! 
  
 (define (a-pythagorean-triple-greater-than low) 
         (let ((high (an-integer-starting-from low))) 
                 (a-pythagorean-triple-between 1 higher))) 

Rptx

  
 ; using a helper procedure to generate integers smaller than a certain number 
  
 (define (an-integer-to n) 
   (require (> n 0)) 
   (amb n (an-integer-to (- n 1)))) 
  
 (define (a-pythagorean-triple) 
   (let ((k (an-integer-from 1))) 
     (let ((j (an-integer-to k))) 
       (let ((i (an-integer-to j))) 
         (require (= (+ (* i i) 
                        (* j j)) 
                     (* k k))) 
         (list i j k)))))