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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (pascal n a) | |
| (cond | |
| ((or | |
| (< n 3) | |
| (= a 1) | |
| (= n a)) 1) | |
| (else | |
| (+ | |
| (pascal (- n 1) (- a 1)) | |
| (pascal (- n 1) a))))) | |