
Recent Posts
Archives
Categories
Monthly Archives: December 2011
SICP solution exercise 1.20
Solution for exercise 1.20 of SICP applicative order —————– 4 remainder operations are performed (gcd 206 40) (if (= 40 0) 206 (gcd 40 (remainder 206 40))) –>> #1 (gcd 40 6) (if (= 6 0) 40 (gcd 6 (remainder … Continue reading
SICP solution exercise 1.18
Solution to exercise 1.18 of SICP sicp_ex_1_18 (define (* e f) (define (double a) (+ a a)) (define (halve a) (floor (/ a 2))) (define (oddresult a b) (if (= 0 (remainder a 2)) 0 b)) (define (multiter a b … Continue reading
SICP solution exercise 1.17
Solution to exercise 1.17 from SICP sicp_ex_1_17 ;invariant: ab + c remains constant during all steps ;if b is odd : ab + c = a(b – 1) + (a + c) ;if b is even : ab + c … Continue reading
SICP solution exercise 1.16
Solution to exercise 1.16 of SICP sicp_ex_1_16 ; exponentiation: iterative process ; loop invariant ab^n is constant (define (exponent b n) (define (even? x) (= (remainder x 2) 0)) (define (expiter b n a) (cond ((= n 0) a) ((even? … Continue reading
SICP solution exercise 1.15
Solution to exercise 1.15 of SICP sicp_ex_1_15 Q1: how many times is p executed when (sine 12.15) is evaluated? A1: use the debugger to find out 1 ]=> (traceentry p) ;Unspecified return value 1 ]=> (sine 12.15) [Entering #[compoundprocedure 15 … Continue reading
SICP solution exercise 1.14
My solution to exercise 1.14 of SICP. sicp_ex_1_14 (countchange 11) ;Value: 4 only 3 coins useable dime = 1/10 $ (d) nickel = 1/20 $ (n) penny = 1/100 $ (p) (countchange 11) ;Value: 4 ways: 11p = 1d + … Continue reading
SICP solutions exercises 1.9 – 1.12
My solutions to exercises 1.9 – 1.12 of SICP. sicp_ex_1_9 a) recursive process (+ 4 5) (inc (+ (dec 4) 5)) (inc (+ 3 5)) (inc (inc (+ (dec 3) 5))) (inc (inc (+ 2 5))) (inc (inc (inc (+ … Continue reading
SICP solutions exercise 1.5 – exercise 1.8
My solutions to exercises 1.5 – 1.8 of SICP. sicp_ex_1_5 ; ANSWER: ; ; Applicativeorder interpreter will start looping infinitively ; trying to evaluate operand (p) in (test 0 (p)). This happens ; at the very start, before even considering … Continue reading
SICP solutions
A few months ago I started reading SICP (Structure and Interpretation of Computer Programs) by Harold Abelson and Gerald Jay Sussman. I’ll blog in this and future posts my solutions to the exercises that I’ve completed until now and as … Continue reading