Monthly Archives: February 2012

SICP solution exercise 1.33

Solution for exercise 1.33 of SICP ; some helper procedures (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-divisor) (else (find-divisor n (+ test-divisor 1))))) (define (divides? a b) … Continue reading

Posted in SICP | Tagged , | Leave a comment

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 null-value term a next b) (if (> a b) null-value (combiner (term a) (accumulate combiner null-value term (next a) next … Continue reading

Posted in SICP | Tagged , | Leave a comment

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

Posted in SICP | Tagged , | Leave a comment

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))

Posted in SICP | Tagged , | Leave a comment