Serendip
Web Studio

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

1.2.2木構造再帰、問題1.11 – SICP(計算機プログラムの構造と解釈)その5

2008年11月11日
blog
sicp

1.2.2 木構造再帰 木構造再帰的プロセスの (fib n)。 (define (fib n) (cond ((= n 0) 0) ((= n 1) 1) (else (+ (fib (- n 1)) (fib (- n 2)))))) (fib 4) (+ (fib (- 4 1)) (fib (- 4 2))) (+ (fib 3) (fib 2)) (+ (+ (fib (- 3 1)) …続きを読む

問題1.9、問題1.10 – SICP(計算機プログラムの構造と解釈)その4

2008年11月10日
blog
sicp

問題1.9 再帰的プロセスと反復的プロセス 次の手続きは再帰的プロセスを生成する。 (define (+ a b) (if (= a 0) b (inc (+ (dec a) b)))) (+ 4 5) (inc (+ (dec 4) 5)) (inc (inc (+ (dec 3) 5))) (inc (inc (inc (+ (dec 2) 5)))) (inc (inc (inc (inc …続きを読む

問題1.8、traceの使い方 – SICP(計算機プログラムの構造と解釈)その3

2008年11月09日
blog
sicp

問題1.8 立方根(cube root)を求める。 (define (cube x) (* x x x)) (define (square x) (* x x)) (define (improve guess x) (/ (+ (/ x (square guess)) (* guess 2.0)) 3.0)) (define (cube-root-iter old-guess new-guess …続きを読む

vim で HTML文字実体参照の変換を行うスクリプト

2008年11月08日
blog
vim

選択範囲を数値文字参照に変換するスクリプト str2numchar.vim – 川o・-・)<2nd life を参考にして HTML文字実体参照(& < > " => &amp; &lt; &gt; &quot;)の変換・逆変換をするvimスクリプトを作った。 スクリプトファイル str2htmlentity.vim…続きを読む

問題1.6、問題1.7 – SICP(計算機プログラムの構造と解釈)その2

2008年11月07日
blog
sicp

問題1.6 (new-if (good-enough? guess x) guess (sqrt-iter (improve guess x) x)) new-if は通常の手続きのため、作用的順序の評価では引数が先に評価されるので、 (good-enough? guess x) が真を返す場合でも (sqrt-iter (improve guess x) x) まで評価されるので、無限ループに陥…続きを読む

PREV 1 2 3 … 61 62 63 64 65 66 67 68 69 70 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 photo php postgresql rails ruby scheme server sicp sqlite ubuntu unix vim webservice windows wordpress youtube
  • Blog (ブログ)
  • Information (お知らせ)
  • Software(ソフトウェア)
  • 2025年12月 (1)
  • 2024年12月 (1)
  • 2023年12月 (1)
  • 2022年12月 (1)
  • 2021年12月 (1)
  • 2020年12月 (1)
  •    過去のアーカイブ
Copyright © Serendip. All rights reserved.
Since 30/Jan/2000.
ページトップへ移動
  • ホーム
  • Blog (ブログ)
  • Information (お知らせ)
  • Software(ソフトウェア)