Created
April 20, 2012 00:37
-
-
Save pilky/2425052 to your computer and use it in GitHub Desktop.
This is a script that will calculate the number of subsets possible in a set of a given size
This file contains hidden or 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 fac(n, limit) | |
if n == 1 | |
return 1 | |
end | |
if n == limit | |
return limit | |
end | |
return n * fac(n - 1, limit) | |
end | |
def calculate_combinations(setsize) | |
combinations = 0 | |
setsize.times do |x| | |
fac_value = (fac(setsize, setsize - x) / fac(x + 1, 1)) | |
#puts "#{x+1}: #{fac_value}" | |
combinations += fac_value | |
end | |
return combinations | |
end | |
number_of_combinations = calculate_combinations(200) | |
puts "Number of combinations: #{number_of_combinations}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment