Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 0.37 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (defn pascals-triangle []
  2.   "Return a lazy seq of rows of Pascal's triangle."
  3.   (letfn [(next-row [row]
  4.             (reduce (fn [v' v] (conj v' (apply +' (take 2 v)))) ; (take 2) returns [1] at the right edge
  5.                     [1]                                         ; Left edge
  6.                     (take (count row) (iterate rest row))))]
  7.     (iterate next-row [1])))