2013-05-28から1日間の記事一覧

問題1.15 をトレースしてみる

(define (cube x) (* x x x )) (define (p x) (- (* 3 x) (* 4 (cube x)))) (define (sine angle) (if (not (> (abs angle) 0.1)) angle (p (sine (/ angle 3.0))))) (require (lib "trace.ss")) (trace p) (sine 12.15) 実行結果 Welcome to DrScheme, vers…

トレースの仕方

DrSchemeでトレースの仕方がわからなかったので調べてみた。 http://d.hatena.ne.jp/chelan/20090508/1241832039こんな風に使うらしい (require (lib "trace.ss")) (trace トレースしたい関数) 問題1.14ならこんな感じ。 (define (count-change amount) (cc …

問題1.14 で心が折れそうなので、とりあえず先に進むことにする

(define (count-change amount) (cc amount 5)) (define (cc amount kinds-of-coins) (cond ((= amount 0) 1) ((or (< amount 0) (= kinds-of-coins 0)) 0) (else (+ (cc amount (- kinds-of-coins 1)) (cc (- amount (first-denomination kinds-of-coins)) …