Serendip
Web Studio

問題1.31a、問題1.31b – SICP(計算機プログラムの構造と解釈)その14

2008年11月19日
blog
sicp

問題1.31 a sum 手続きとほぼ同じ形で表せる(+ が * になる)。 ただし、a > b の際の戻り値が1となる。 (define (product term a next b) (if (> a b) 1 (* (term a) (product term (next a) next b)))) product を使って factorial を書く。 (define (fac…続きを読む

問題1.30 – SICP(計算機プログラムの構造と解釈)その13

2008年11月19日
blog
sicp

問題1.30 線形再帰の sum 手続き (define (sum1 term a next b) (if (> a b) 0 (+ (term a) (sum1 term (next a) next b)))) a から b までの整数の和(線形再帰手続き) (define (sum-integers1 a b) (define (identify x) x) (define (inc x…続きを読む

問題1.29 – SICP(計算機プログラムの構造と解釈)その12

2008年11月18日
blog
sicp

問題1.27 パス 問題1.28 パス 問題1.29 うーん、Simpsonの公式を使った方が精度が落ちているような気がする… (define (cube x) (* x x x)) (define (inc x) (+ x 1)) (define (sum term a next b) (if (> a b) 0 (+ (term a) (sum term (next a) n…続きを読む

問題1.24、問題1.26 – SICP(計算機プログラムの構造と解釈)その11

2008年11月17日
blog
sicp

問題1.24 計算量は Θ(log n) の増加なので 1,000:1,000,000 は 1:2 程度と予想される。 結果を見ると 1:4 ぐらいになっている。 (define (square n) (* n n)) (define (smallest-divisor n) (find-divisor n 2)) (define (find-divisor n test-divisor…続きを読む

問題1.21、問題1.22、問題1.23 – SICP(計算機プログラムの構造と解釈)その10

2008年11月16日
blog
sicp

問題1.21 (define (square n) (* n n)) (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-divis…続きを読む

問題1.19、問題1.20 – SICP(計算機プログラムの構造と解釈)その9

2008年11月15日
blog
sicp

問題1.19 p’ : (+ (* p p) (* q q)) q’ : (+ (* 2 p q) (* q q)) 問題1.20 (define (gcd a b) (if (= b 0) a (gcd b (remainder a b)))) 正規順序の置き換えの場合。赤字部分が実行される remainder。 remainder を rem と省略表記している。 18回。 (gcd 206 …続きを読む

問題1.16、問題1.17、問題1.18 – SICP(計算機プログラムの構造と解釈)その8

2008年11月14日
blog
sicp

問題1.16 不変量 ab^n について、答えを見れば「ああ、そういうことか」と解るけれども、自分の頭ではこのような計算が思い浮かばない… (define (fast-expt-iter b n) (expt-iter b n 1)) (define (expt-iter b n a) (cond ((= n 0) a) ((even? n) (expt-iter (* b b) (/…続きを読む

Gauche でリーダーマクロ #?= を使ったデバッグ

2008年11月14日
blog
scheme

Scheme処理系の Gauche で #?= を使って printf debug をする。 #?=expr は (debug-print expr) と置き換えられ expr を評価して結果を返す。 結果を返す前後に、評価式とその値を print する。 使用例 再帰的プロセスの factorial gosh> (define (factorial n) (if (= n 1) 1 (* …続きを読む

問題1.14、問題1.15 – SICP(計算機プログラムの構造と解釈)その7

2008年11月13日
blog
sicp

問題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)) (c…続きを読む

問題1.12 – SICP(計算機プログラムの構造と解釈)その6

2008年11月12日
blog
sicp

問題1.12 パスカルの三角形(Pascal’s triangle)の上から n 行目、左から k 番目の値を求める式。 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 (define (pascals-triangle n k) (if (or (= n k) (= k 1)) 1 (+ (pascals-tr…続きを読む

PREV 1 2 3 … 60 61 62 63 64 65 66 67 68 69 NEXT
serendipity [sèrəndípəti]
ものをうまく発見する能力、幸運な発見
actionscript android angularjs arduino clojure cms css design eclipse emacs firefox flash git golang graphic hardware heroku html java javascript language-c linux mac manual mysql ooo perl php postgresql rails ruby scheme server sicp sqlite ubuntu unix vim webservice windows wordpress youtube
  • Blog (ブログ)
  • Information (お知らせ)
  • Software(ソフトウェア)
  • 2021年12月 (1)
  • 2020年12月 (1)
  • 2019年2月 (1)
  • 2018年4月 (1)
  • 2017年4月 (1)
  • 2016年12月 (1)
  •    過去のアーカイブ
Copyright © Serendip. All rights reserved.
Since 30/Jan/2000.
ページトップへ移動
  • ホーム
  • Blog (ブログ)
  • Information (お知らせ)
  • Software(ソフトウェア)