Read Exercise 3.69 ~ Solution
(define (triples s t u)
(cons-stream
(list
(stream-car s)
(stream-car t)
(stream-car u))
(interleave
(stream-map
(lambda (x) (append (list (stream-car s)) x))
(stream-cdr (pairs t u)))
(triples
(stream-cdr s)
(stream-cdr t)
(stream-cdr u)))))
(define pythagorean-triples
(stream-filter (lambda (t)
(= (+ (square (car t))
(square (cadr t)))
(square (caddr t))))
(triples integers integers integers) ))
(show-stream pythagorean-triples 5)
(3 4 5)
(6 8 10)
(5 12 13)
(9 12 15)
(8 15 17)
done
[…] that the constraint on the maximum value of j is valid. Having said that, all of the values from Exercise 3.69 came up in this version and searching for more solutions is much faster than the streams version. […]