Skip to content

Instantly share code, notes, and snippets.

@begriffs
Created February 4, 2012 04:19
Show Gist options
  • Save begriffs/1735310 to your computer and use it in GitHub Desktop.
Save begriffs/1735310 to your computer and use it in GitHub Desktop.
Calculate values for cells in Pascal's triangle
def pascal(row, pos)
throw :badArguments if pos > row or pos < 0 or row < 0
def fact(n); 1.upto(n).inject(:*) || 1; end
fact(row) / (fact(pos) * fact(row - pos))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment