앗.. 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
머리가 굳었다 흑흑
문제는 다음과 같다. 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
머리가 굳었다 흑흑




덧글