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

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 n a)
(cond
((or
(< n 3)
(= a 1)
(= n a)) 1)
(else
(+
(pascal (- n 1) (- a 1))
(pascal (- n 1) a)))))

Discover more from Gaurav Sharma's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading