6 kyu
Pascal's Triangle #2
1,838 of 5,834Jeroko
Description:
Here you will create the classic Pascal's triangle.
Your function will be passed the depth of the triangle and your code has to return the corresponding Pascal's triangle up to that depth.
The triangle should be returned as a nested array. For example:
pascal(5) -> [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]
To build the triangle, start with a single 1
at the top, for each number in the next row you just take the two numbers above it and add them together, except for the edges, which are all 1
. e.g.:
1
1 1
1 2 1
1 3 3 1
Arrays
Algorithms
Similar Kata:
Stats:
Created | Nov 26, 2013 |
Published | Nov 26, 2013 |
Warriors Trained | 12967 |
Total Skips | 2968 |
Total Code Submissions | 18396 |
Total Times Completed | 5834 |
JavaScript Completions | 1838 |
Ruby Completions | 532 |
Python Completions | 2185 |
Java Completions | 1082 |
Clojure Completions | 83 |
Scala Completions | 41 |
C# Completions | 150 |
Haskell Completions | 39 |
λ Calculus Completions | 7 |
Julia Completions | 16 |
Total Stars | 220 |
% of votes with a positive feedback rating | 87% of 750 |
Total "Very Satisfied" Votes | 593 |
Total "Somewhat Satisfied" Votes | 114 |
Total "Not Satisfied" Votes | 43 |