read

SICP 연습문제 풀이

(define (square x) (* x x))

(define (f b n)
  (cond ((= n 0) 1)
        ((= n 1) b)
        ((even? n) (f (square b) (/ n 2)))
        (else (* b (f b (- n 1))))))

(define (g b n)
  (define (g-iter b n a)
    (cond ((= n 0) a)
          ((even? n) (g-iter (square b) (/ n 2) a))
          (else (g-iter b (- n 1) (* a b)))))
  (g-iter b n 1))

프로시져 g 가 문제가 원하는 답이다.

Blog Logo

Ki Sung Bae


Published

Image

Gsong's Blog

Developer + Entrepreneur = Entreveloper

Back to Overview