Chat (Lingr.com)
Informaiton
Daily
Column
- MySQL日本語の旅(5/1)
- アクセス向上秘伝(5/9)
- 一風変ったHaskellλ門(6/13)
- SICP Answer Book (5/31) 問題3.26追加
Zope Solution
Extra
アーカイブ
OSS案内所
Site Info
関連リンク
##(link2sicp "book-Z-H-11.html#%_thm_1.27" "Exercise 1.27")
解答例
(define (fermat-test2 n)
(define (try-it a)
(= (expmod a n n) a))
(define (iter a)
(if (= a 1)
#t
(and (try-it a)
(iter (- a 1)))))
(iter (- n 1)))
実行結果(fermat-test2 は素数と判定した場合に #t を返す)
gosh> (fermat-test2 561) #t gosh> (fermat-test2 1105) #t gosh> (fermat-test2 1729) #t gosh> (fermat-test2 2465) #t gosh> (fermat-test2 2821) #t gosh> (fermat-test2 6601) #t
コード
##(sicp-answer-code "ex-1.27.scm")