Skip to content

Instantly share code, notes, and snippets.

@enigmaticape
Created November 4, 2012 16:31
Show Gist options
  • Save enigmaticape/4012514 to your computer and use it in GitHub Desktop.
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
;; 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) ) )))
@enigmaticape
Copy link
Author

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment