SICP 연습문제 1.16 학술

앗.. exponent인데 반사적으로 구글 그룹쪽에는 expr이라고 써버렸다 orz..

문제는 다음과 같다. fast-expt처럼 계산 시간이 로그 비례로 늘어나게끔 계속 제곱하는 방법을 쓰되, 되풀이 프로세스를 펼쳐내는 거듭제곱 프로시저를 짜보자.

참고로 fast-expt는 아래와 같이 정의되어 있었다.

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

> (define (fast-expt-iter b counter product)
    (if (= counter 0)
        product
        (if (even? counter)
            (fast-expt-iter (* b b) (/ counter 2) product)
            (fast-expt-iter b (- counter 1) (* product b)))))
> (fast-expt-iter 2 10 1)
1024
> (fast-expt-iter 2 12 1)
4096
> (fast-expt-iter 2 11 1)
2048

머리가 굳었다 흑흑

트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://xeraph.com/tb/4011998 [도움말]

핑백

  • Xeraph beyond the Great Firewall : 2008년 회고록 (작성 중) 2008-12-18 00:05:13 #

    ... 코드 북SICP 3차 모임 발제 및 문제 풀이 할당SICP 연습문제 1.21 ~ 24 발판SICP 연습문제 1.13SICP 연습문제 1.11SICP 연습문제 1.16Rails 2.0 PADOCON2008 형태소분석 메타스플로잇 Lucene, BDB, Inverted Index 얼랭 베타 리딩 코드 ... more

덧글

댓글 입력 영역