Skip to content

Instantly share code, notes, and snippets.

@landau
Last active August 29, 2015 13:58
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 landau/10009590 to your computer and use it in GitHub Desktop.
Save landau/10009590 to your computer and use it in GitHub Desktop.
Gets the nth row of Pascal
(defn pascal
"Gets the nth row of a pascal triangle."
[n]
(nth
(iterate #(vec (map + (conj % 0) (cons 0 %))) [1N])
(dec n)))
; user=> (pascal 10)
; [1 9 36 84 126 126 84 36 9 1]
; user=> (pascal 25)
; [1N 24N 276N 2024N 10626N 42504N 134596N 346104N 735471N 1307504N 1961256N 2496144N 2704156N 2496144N 1961256N 1307504N 735471N 346104N 134596N 42504N 10626N 2024N 276N 24N 1N]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment