4月 16th, 2008 at 6:46am |
MHP2Gばっかやっててすいませんすいませんすいません
お勉強サボっちゃダメ!絶対!(でもサボる
問題 1.29
PLAIN TEXT
SCHEME:
(define (sum term a next b)
(if (> a b)
0
(+ (term a)
(sum term (next a) next b))))
(define (cube x) (* x x x))
(define (simpson f1 a b n)
(define h (/ (- b a) n))
(define (y [...]
Read the rest of SICPその7
4月 3rd, 2008 at 11:10pm |
メモ
(auto-load-path "D:\\Scheme\\code")
(load "1.21.scm")
↑楽 Gauche用
問 1.21
PLAIN TEXT
SCHEME:
(define (smallest-divisor n)
(find-divisor n 2))
(define (find-divisor n test-divisor)
(cond ((> (square test-divisor) n) n)
((divides? test-divisor n) test-divisor)
(else (find-divisor n (+ test-divisor 1)))))
(define (divides? a b)
(= (remainder b a) 0))
(define (square x)
(* x x))
(smallest-divisor 199) ;199
(smallest-divisor [...]
Read the rest of SICP その6
4月 3rd, 2008 at 2:13am |
問題 1.16
PLAIN TEXT
SCHEME:
(define (square x) (* x x))
(define (fast-expt1 b n)
(cond ((= n 0) 1)
((even? n) (square (fast-expt1 b (/ n 2))))
(else (* b (fast-expt1 b (- n 1))))))
(define (fast-expt2 b n)
(define (iter b n a)
[...]
Read the rest of SICP その5