šŸ“
SICP
  • README
  • Building Abstractions With Procedures
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
Powered by GitBook
On this page
  • 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. Write a procedure that computes elements of Pascal’s triangle by means of a recursive process.

Was this helpful?

  1. Building Abstractions With Procedures

12

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

         1
       1   1
     1   2   1
   1   3   3   1
 1   4   6   4   1
       . . .

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. Write a procedure that computes elements of Pascal’s triangle by means of a recursive process.

(define (P row col) (cond ((= col 1) 1) ((= row col) 1) (else (+ (P (- row 1) (- col 1)) (P (- row 1) col)))))
(P 5 1)
(P 5 2)
Previous11Next13

Last updated 4 years ago

Was this helpful?