Skip to content

Instantly share code, notes, and snippets.

@chrisberkhout
Created April 3, 2013 05:20
Show Gist options
  • Save chrisberkhout/5298628 to your computer and use it in GitHub Desktop.
Save chrisberkhout/5298628 to your computer and use it in GitHub Desktop.
Generate a row of Pascal's triangle, in Ruby
def pt(row)
return [1] if row == 0
return [1, 1] if row == 1
last = pt(row-1)
[1] + (0..row-2).to_a.map { |i| last[i] + last[i+1] } + [1]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment