Skip to content

Instantly share code, notes, and snippets.

@dkua
Created March 8, 2015 06:34
Show Gist options
  • Save dkua/ddf5333266b95370c808 to your computer and use it in GitHub Desktop.
Save dkua/ddf5333266b95370c808 to your computer and use it in GitHub Desktop.
SICP Exercise 1.12
#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