Created
September 19, 2013 12:48
-
-
Save softr8/6622944 to your computer and use it in GitHub Desktop.
pascal's triangle in ruby
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
def pascalsTriangle(n) | |
(1..n).inject([]) do |final, level| | |
final << (1..level).inject([]) do |horizontal, index| | |
if index == 1 || index == level | |
horizontal << 1 | |
else | |
horizontal << (final[level - 2][index - 2]) + (final[level - 2][index - 1]) | |
end | |
end | |
final | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment