Skip to main content.
-->
June 19th, 2005

Solution to SICP Exercise 1.27

Solution to Exercise 1.27:

Here is the procedure for testing whether a number is a Charmichael number:

(define (congruent? n a)
  (= (expmod a n n) a))
 
(define (carmichael? n)
  (define (iter i)
    (cond ((= i 0) #t)
          ((congruent? n i) (iter (- i 1)))
          (else #f)))
  (iter (- n 1)))

Posted by Ken Dyck in Programming

This entry was posted on Sunday, June 19th, 2005 at 12:56 pm and is filed under Programming. You can follow any responses to this entry through the comments RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>