(wat-aro)

生きてます

2015-11-06から1日間の記事一覧

SICP 問題 3.06

;; オリジナルのrand (define rand (let ((x random-init)) (lambda () (set! x (rand-update x)) x))) ;; 'generateで乱数生成,'resetで引数の数字で初期化するrand (define rand (let ((x random-init)) (define (reset new-rand) (set! x new-rand) x) (…

SICP 問題 3.5

(use srfi-27) (define (random-in-range low high) (let ((range (- high low))) (+ low (* (random-real) range)))) ;; 問題分には(+ low (random range))となっている. (define (estimate-integral P x1 x2 y1 y2 trials) (let ((x-length (- x2 x1)) (y…

SICP 問題 3.4

(define (make-account balance password) (let ((counter 0)) (define (withdraw amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds")) (define (deposit amount) (set! balance (+ balance amount)…