练习3-71
原文
代码
(define (Ramanujan s)
(define (stream-cadr s) (stream-car (stream-cdr s)))
(define (stream-cddr s) (stream-cdr (stream-cdr s)))
(let ((scar (stream-car s))
(scadr (stream-cadr s)))
(if (= (sum-triple scar) (sum-triple scadr))
(cons-stream (list (sum-triple scar) scar scadr)
(Ramanujan (stream-cddr s)))
(Ramanujan (stream-cdr s)))))
(define (triple x) (* x x x))
(define (sum-triple x) (+ (triple (car x)) (triple (cadr x))))
(define Ramanujan-numbers
(Ramanujan (weighted-pairs integers integers sum-triple)))
所以接下来的5个数是:
(4104 (2 16) (9 15))
(13832 (2 24) (18 20))
(20683 (10 27) (19 24))
(32832 (4 32) (18 30))
(39312 (2 34) (15 33))
时间: 2024-11-10 10:38:17