Created
April 30, 2012 20:09
-
-
Save agentultra/2562306 to your computer and use it in GitHub Desktop.
A function to calculate n rows of Pascal's Triangle
This file contains hidden or 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
(defun triangle (num) | |
"Generate num rows of Pascal's Triangle" | |
(labels ((next-row (row last-num) | |
(cond ((null row) '(1)) | |
(t (cons (+ last-num (car row)) | |
(next-row (cdr row) (car row)))))) | |
(triangle-b (num prev-row) | |
(cond ((= num 0) '()) | |
(t (cons prev-row | |
(triangle-b (1- num) | |
(next-row prev-row 0))))))) | |
(triangle-b num '(1)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment