Skip to content

Instantly share code, notes, and snippets.

@ecounysis
Created March 27, 2010 01:37
Show Gist options
  • Save ecounysis/345616 to your computer and use it in GitHub Desktop.
Save ecounysis/345616 to your computer and use it in GitHub Desktop.
(define pascal
(lambda (x)
(letrec ([last
(lambda (x)
(if (null? (cdr x)) x (last (cdr x))))]
[sum-two
(lambda (x)
(+ (car x) (cadr x)))]
[sum-doubles
(lambda (x)
(cond ((null? (cdr x)) (last x))
(else (cons (sum-two x) (sum-doubles (cdr x))))))]
[pascal-sub
(lambda (x)
(cons (car x) (sum-doubles x)))])
(cond ((= x 1) (list 1))
(else (pascal-sub (pascal (- x 1))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment