Created
November 4, 2012 16:31
-
-
Save enigmaticape/4012514 to your computer and use it in GitHub Desktop.
Recursivley compute the elements of Pascal's triangle in Scheme. Answer to SICP exercise 1.12
This file contains 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
;; Recursive function to compute the elements | |
;; of Pascal's triangle. Note the complete lack | |
;; of any sanity checks on the input. GIGO. | |
(define (pelem row col) | |
(cond((= col 0) 1) | |
((= col row) 1) | |
(else(+(pelem(- row 1)(- col 1)) | |
(pelem(- row 1) col) ) ))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Recursivley compute the elements of Pascal's triangle in Scheme. Solution to SICP exercise 1.12, discussed at http://www.enigmaticape.com/blog/sicp-exercise-1-12-pascals-triangle-recursively/