Last active
August 29, 2015 13:58
-
-
Save landau/10009590 to your computer and use it in GitHub Desktop.
Gets the nth row of Pascal
This file contains 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
(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