Skip to content

Instantly share code, notes, and snippets.

@joegiralt
Created January 21, 2015 21:38
Show Gist options
  • Save joegiralt/601d95496c49b4988fa2 to your computer and use it in GitHub Desktop.
Save joegiralt/601d95496c49b4988fa2 to your computer and use it in GitHub Desktop.
n choose k Ruby
class Integer
def choose(k)
return 0 if (k > self)
n = self
r = 1
1.upto(k) do |d|
r *= n
r /= d
n -= 1
end
return r
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment