码迷,mamicode.com
首页 > 其他好文 > 详细

【SICP练习】140 练习3.71

时间:2015-03-29 12:21:38      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

练习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))

【SICP练习】140 练习3.71

标签:

原文地址:http://blog.csdn.net/nomasp/article/details/44725421

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!