Created
March 8, 2015 06:34
-
-
Save dkua/ddf5333266b95370c808 to your computer and use it in GitHub Desktop.
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
#lang scheme | |
(define (fact n) | |
(fact-tail n 1)) | |
(define (fact-tail n acc) | |
(if (= 0 n) | |
acc | |
(fact-tail (- n 1) (* acc n)))) | |
(define (pascal k n) | |
(cond | |
((= k 0) 1) | |
((= k n) 1) | |
((> k n) 0) | |
(else | |
(/ (fact n) (* (fact k) (fact (- n k))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment