Created
March 1, 2014 07:10
-
-
Save fernviridian/9286350 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
def factorial(count) | |
fact = 0 | |
if count >= 0 | |
fact = (factorial(count-1))*count | |
end | |
if count == 0 | |
fact = 1 | |
end | |
fact | |
end | |
input1 = Integer(ARGV[0]) #N | |
input2 = Integer(ARGV[1]) #R | |
#excuse my shitty ruby por favor | |
print "FACTORIAL OF " | |
print input1 | |
print " IS " | |
puts factorial(input1) | |
print "COMBINATION OF " | |
print input1 | |
print " choose " | |
print input2 | |
print " is: " | |
nfac = factorial(input1) | |
rfac = factorial(input2) | |
bottom = rfac * factorial(input1-input2) | |
combinations = nfac / bottom | |
puts combinations | |
print "PERMUTATION OF " | |
print input1 | |
print " choose " | |
print input2 | |
print " is: " | |
permutation = nfac / factorial(input1-input2) | |
puts permutation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment