Exercise 3.72. In a similar way to exercise 3.71 generate a stream of all numbers that can be written as the sum of two squares in three different ways (showing how they can be so written). ———————————————————————————————————————————————————————————————————————— (define (cube-sum pair) (+ (expt (car pair) 3) (expt (cadr pair) 3))) (define pairs-by-cube-sum (weighted-pairs integers integers cube-sum)) (define (weight-equal stream weight) (define (go stream pair target) (let* ((next-pair (stream-car stream)) (next-weight (weight next-pair))) (if (= next-weight target) (let* ((third-pair (stream-cadr stream)) (third-weight (weight third-pair))) (if (= third-weight target) (cons-stream (list pair next-pair third-pair) (go (stream-cdr stream) next-pair next-weight)) (go (stream-cdr stream) next-pair next-weight))) (go (stream-cdr stream) next-pair next-weight)))) (go (stream-cdr stream) (stream-car stream) (weight (stream-car stream)))) (define ramanujan-triples (weight-equal pairs-by-cube-sum cube-sum)) The first few are: ((255 414) (228 423) (167 436)) ((346 428) (90 492) (11 493)) ((408 423) (359 460) (111 522)) ((315 525) (198 552) (70 560))