2015/12/16
SICP 問題 3.71
問題文通りに.
ラマヌジャン数のストリームを作る.
(define (sum-cube x)
(let ((a (car x))
(b (cadr x)))
(+ (* a a a) (* b b b))))
(define (ramanujan stream)
(let ((s1 (stream-car stream))
(s2 (stream-car (stream-cdr stream))))
(let ((weight1 (sum-cube s1))
(weight2 (sum-cube s2)))
(cond ((= weight1 weight2)
(cons-stream weight1
(ramanujan (stream-cdr stream))))
(else
(ramanujan (stream-cdr stream)))))))
(define ramanujan-number
(ramanujan (weighted-pairs integers integers sum-cube)))
gosh> (stream-head ramanujan-number 6)
1729
4104
13832
20683
32832
39312
done