SICP
function avg(x, y) { return (x + y) / 2; } function abs(x) { return (x >= 0) ? x : -x; } function zelo_point(f, neg, pos) { var mid = avg(neg, pos); return abs(pos - neg) < 0.001 ? mid : f(mid) < 0 ? zelo_point(f, mid, pos) : f(mid) > 0 ? …
function abs(x) { return (x >= 0) ? x : -x; } function fixed(f, guess) { var next = f(guess); return abs(guess - next) < 0.001 ? next : fixed(f, next); } print(fixed(Math.cos, 1)); テキストのほうは、もちょっと長かったような。 テキスト欄外…
亀の歩みだ…
さっぱりわからん…
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html#%_sec_1.1.6以下、問題の(僕の)解答です。
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html#%_sec_1.1.6以下、問題の(僕の)解答です。
function gdc(a, b) { return (b == 0) ? a : gdc(b, (a % b)); } print(gdc(10, 4)); print(gdc(35, 21)); print(gdc(150, 36));
#!/usr/bin/env scheme (define (log name) (begin (display name) (newline) #t)) (define (f-test) (log "f-test")) (define (f-then) (log "f-then")) (define (f-else) (log "f-else")) (define (new-if x y z) (cond (x y) (else z))) (display (if (f-…
#!/usr/bin/env rhino function car(a) { return a[0]; } function cdr(a) { var na = []; var i=1; for(; i