Skip to content

Instantly share code, notes, and snippets.

@raimusyndrome
Created July 24, 2014 06:30
Show Gist options
  • Save raimusyndrome/9ee3bd34aeb9aaf65262 to your computer and use it in GitHub Desktop.
Save raimusyndrome/9ee3bd34aeb9aaf65262 to your computer and use it in GitHub Desktop.
階乗、順列の数、組み合わせの数を求める
class Integer
def combination(k)
self.factorial/(k.factorial*(self-k).factorial)
end
def permutation(k)
self.factorial/(self-k).factorial
end
def factorial
return 1 if self == 0
(1..self).inject(:*)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment