灯下 登录
计算机科学 / SICP / 3.5.3 Exploiting the Stream Paradigm

Exercise 3.69 · 习题

Exercise 3.69: Write a procedure triples
that takes three infinite streams, S, T, and U, and produces the
stream of triples (

S
i

,

T
j

,

U
k

) such that i

j

k.
Use triples to generate the stream of all Pythagorean
triples of positive integers, i.e., the triples (
i
,
j
,
k
) such that
i

j and i
2

+

j
2

=

k

2.

练习 3.69:编写过程 triples,它接受三个无穷流 S、T、U,产生满足 i ≤ j ≤ k 的三元组 (Sᵢ, Tⱼ, Uₖ) 的流。用 triples 生成所有正整数的毕达哥拉斯三元组 (Pythagorean triples) 的流,即满足 i ≤ j 且 i² + j² = k² 的三元组 (i, j, k)。