Created
July 24, 2014 06:30
-
-
Save raimusyndrome/9ee3bd34aeb9aaf65262 to your computer and use it in GitHub Desktop.
階乗、順列の数、組み合わせの数を求める
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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