
Recent Posts
Archives
Categories
Monthly Archives: February 2012
SICP solution exercise 1.33
Solution for exercise 1.33 of SICP ; some helper procedures (define (smallestdivisor n) (finddivisor n 2)) (define (finddivisor n testdivisor) (cond ((> (square testdivisor) n) n) ((divides? testdivisor n) testdivisor) (else (finddivisor n (+ testdivisor 1))))) (define (divides? a b) … Continue reading
SICP solution exercise 1.32
Solution to exercise 1.32 of SICP. Solution where accumulate generates a recursive process: ; accumulate: recursive process (define (accumulate combiner nullvalue term a next b) (if (> a b) nullvalue (combiner (term a) (accumulate combiner nullvalue term (next a) next … Continue reading
SICP solution exercise 1.31
Solution to exercise 1.31 of SICP. Recursive process: (define (product factor a next b) (if (> a b) 1 (* (factor a) (product factor (next a) next b)))) factorial defined in terms of product: (define (identity a) a) (define (inc … Continue reading
SICP solution exercise 1.30
Solution for exercise 1.30 of SICP (define (sum term a next b) (define (iter a result) (if (> a b) result (iter (next a) (+ result (term a))))) (iter a 0))