開発環境
計算機プログラムの構造と解釈[第2版](ハロルド エイブルソン (著)、ジュリー サスマン (著)、ジェラルド・ジェイ サスマン (著)、Harold Abelson (原著)、Julie Sussman (原著)、Gerald Jay Sussman (原著)、和田 英一 (翻訳)、翔泳社、原著: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の第1章(手続きによる抽象の構築)、1.2(手続きとその生成するプロセス)、1.2.6(例: 素数性のテスト)、問題1.21.を取り組んでみる。
その他参考書籍
問題1.21.
コード(Emacs)
(begin
(newline)
(load "procedures.scm")
(define nums '(199 1999 19999))
(define (smallest-divisor n)
(find-divisor n 2))
(define (find-divisor n test-divisor)
(if (> (square test-divisor) n)
n
(if (divides? test-divisor n)
test-divisor
(find-divisor n (+ test-divisor 1)))))
(define (divides? a b)
(= (remainder b a) 0))
(display nums)
(newline)
(display (map smallest-divisor nums))
(newline)
'done)
入出力結果(Terminal(kscheme), REPL(Read, Eval, Print, Loop))
$ ksi < sample21.scm ksi> (199 1999 19999) (199 1999 7) => done ksi> $
0 コメント:
コメントを投稿