(wat-aro)

無職から有職者にランクアップしました

SICP 問題1.27

(define (carmichael-test n)
  (define (try-loop a)
    (cond ((= a n) true)
          ((= (expmod a n n) a) (try-loop (+ a 1)))
          (else false)))
  (try-loop 1))
gosh> (carmichael-test 561)
#t
gosh> (prime? 561)
#f
gosh> (carmichael-test 1105)
#t
gosh> (prime? 1105)
#f
gosh> (carmichael-test 1729)
#t
gosh> (prime? 1729)
#f
gosh> (carmichael-test 2465)
#t
gosh> (prime? 2465)
#f
gosh> (carmichael-test 2821)
#t
gosh> (prime? 2821)
#f
gosh> (carmichael-test 6601)
#t
gosh> (prime? 6601)
#f