Solution to Exercise 1.12:
(define (pascal row col)
(cond ((or (= 0 col) (= row col)) 1)
(else (+ (pascal (- row 1) (- col 1))
(pascal (- row 1) col)))))
Posted by Ken Dyck in Programming
About
![]()
Links
Search
Categories
Archives
Subscribe
Ads
Solution to Exercise 1.12:
(define (pascal row col)
(cond ((or (= 0 col) (= row col)) 1)
(else (+ (pascal (- row 1) (- col 1))
(pascal (- row 1) col)))))
Posted by Ken Dyck in Programming
I have the same procedure but I just added some protective conditions to deal wonky input such as:
(note: I consider rows and cols to both begin with index 0)
col gt row, row lt 0, col lt 0