Skip to content

Instantly share code, notes, and snippets.

@softr8
Created September 19, 2013 12:48
Show Gist options
  • Save softr8/6622944 to your computer and use it in GitHub Desktop.
Save softr8/6622944 to your computer and use it in GitHub Desktop.
pascal's triangle in ruby
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