Skip to content

Instantly share code, notes, and snippets.

@guns
Created January 6, 2012 00:13
Show Gist options
  • Save guns/1568130 to your computer and use it in GitHub Desktop.
Save guns/1568130 to your computer and use it in GitHub Desktop.
Pascal's triangle, iterative
(defn pascals-triangle []
"Return a lazy seq of rows of Pascal's triangle."
(letfn [(next-row [row]
(reduce (fn [v' v] (conj v' (apply +' (take 2 v)))) ; (take 2) returns [1] at the right edge
[1] ; Left edge
(take (count row) (iterate rest row))))]
(iterate next-row [1])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment