Created
July 11, 2011 12:33
-
-
Save ghoseb/1075752 to your computer and use it in GitHub Desktop.
Psacal's Functional 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
(ns pascal) | |
(defn next-row | |
"Given one row, generate the next one." | |
[row] | |
(vec (map + (concat [0] row) (concat row [0])))) | |
(defn pascal | |
"Generate an infinite lazy sequence of Pascal rows." | |
[] | |
(iterate next-row [1])) | |
;;; Usage | |
(comment | |
(def pascals-triangle (pascal)) | |
(take 10 pascals-triangle)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice! easier to grok than Tyo's solution using partial.