2008-05-01から1ヶ月間の記事一覧

問題 2.1

(define (gcd a b) (if (= b 0) a (gcd b (remainder a b)))) (define (make-rat n d) (let ((g (gcd n d))) (let ((ng (/ n g)) (dg (/ d g))) (if (< ng 0) (cons (- ng) (- dg)) (cons ng dg))))) ;(define (make-rat n d) ; (let ((g (gcd n d))) ; (con…

計算機プログラムの構造と解釈(SICP)

1.45 (define (pow x y) (define (pow-iter x y p) (if (<= y 0) p (pow-iter x (- y 1) (* p x)))) (pow-iter x y 1)) (define (avarage x y) (/ (+ x y) 2.0)) (define (fixed-point f first-guess) (define tolerance 0.0000000001) (define (close-enoug…

計算機プログラムの構造と解釈(SICP)

1.39 (define (pow x y) (cond ((= y 0) 1) ((= y 1) x) (else (* x (pow x (- y 1)))))) (define (cont-frac f n d k) (define (cont-frac-iter f n d k i) (if (= k i) (/ (n i) (d i)) (/ (n i) (f (d i) (cont-frac-iter f n d k (+ i 1)))))) (cont-fra…