Skip to content

Instantly share code, notes, and snippets.

@dliberalesso
Created December 5, 2013 19:30
Show Gist options
  • Save dliberalesso/7811852 to your computer and use it in GitHub Desktop.
Save dliberalesso/7811852 to your computer and use it in GitHub Desktop.
Script to generate a Pascal's Triangle.
def pascalsTriangle(n = 1)
return nil if n == nil || n < 1
rows = [[1]]
2.upto(n) do |i|
row = [1]
1.upto(i-2) do |j|
row << rows.last[(j-1) % rows.last.size] + rows.last[j % rows.last.size]
end
rows << (row << 1)
end
rows.flatten
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment