SICP Problem 1.12

Had a little time and got it done quicker than I expected. Problem 1.12 was to write a procedure to calculate elements of pascals triangle. I took that to mean calculate the value at position n of a given row. Take a look -

(define (pascal row n)   (cond ((> n row) 0)         ((or (= n 1) (= n row)) 1)         (else (+ (pascal (- row 1) n) (pascal (- row 1) (- n 1))))))

Leave a comment