開発環境
- OS X Lion - Apple(OS)
- Emacs、BBEdit - Bare Bones Software, Inc. (Text Editor)
- プログラミング言語: MIT/GNU Scheme
計算機プログラムの構造と解釈(Gerald Jay Sussman(原著)、Julie Sussman(原著)、Harold Abelson(原著)、和田 英一(翻訳)、ピアソンエデュケーション、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の3(標準部品化力, オブジェクトおよび状態)、3.5(ストリーム)、3.53(ストリームパラダイムの開発)、対の無限のストリーム、問題 3.71を解いてみる。
その他参考書籍
問題 3.71
コード(BBEdit)
sample.scm
(define (cube x)
(* (squre x) x))
(define (weight-cube pair)
(+ (cube (car pair)) (cube (cadr pair))))
(define pairs-weighted-cube
(weighted-pairs integers integers weight-cube))
(define (ramanujan s w)
(let ((p1 (stream-car s))
(p2 (stream-car (stream-cdr s))))
(let ((w1 (weight-cube p1))
(w2 (weight-cube p2)))
(cond ((= w1 w)
(ramanujan (stream-cdr s) w))
((= w1 w2)
(cons-stream w1
(ramanujan (stream-cdr (stream-cdr s))
w1)))
(else
(ramanujan (stream-cdr s) 0))))))
(define ramanujan-number
(ramanujan pairs-weighted-cube 0))
0 コメント:
コメントを投稿