Matt Bowcock // mbowcock.com

SICP Problem 1.12

with one comment

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

Written by matt

October 9th, 2009 at 3:20 pm

Posted in notebook

Tagged with

One Response to 'SICP Problem 1.12'

Subscribe to comments with RSS or TrackBack to 'SICP Problem 1.12'.

  1. Another version with isEdge procedure.

    (define (pascalTriangle row col)
    (if (isEdge row col)
    1
    (+
    (pascalTriangle (- row 1) col)
    (pascalTriangle (- row 1) (- col 1))
    )

    )
    )

    (define (isEdge row col)
    (or (= col 1) (= row col))
    )

    Kalecser

    18 Jan 10 at 7:33 pm

Leave a Reply