SICP exercises 1.2 cont. 2

Again only one problem. I’ll need to be more motivated.

1.12

The following pattern of numbers is called Pascal’s triangle.

pascal

The numbers at the edge of the triangle are all 1, and each number inside the triangle is the sum of the two numbers above it.35 Write a procedure that computes elements of Pascal’s triangle by means of a recursive process.

(define (pascal row nth)
  (cond  ((or (= nth row) (= nth 1))
          1)
         ((< nth 0)
          0)
         (else
          (+ (pascal (- row 1) nth) (pascal (- row 1) (- nth 1))))))
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s