Skip to content

Instantly share code, notes, and snippets.

@ghoseb
Created July 11, 2011 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghoseb/1075752 to your computer and use it in GitHub Desktop.
Save ghoseb/1075752 to your computer and use it in GitHub Desktop.
Psacal's Functional Triangle
(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))
@vedang
Copy link

vedang commented Jul 11, 2011

nice! easier to grok than Tyo's solution using partial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment