Skip to content

Instantly share code, notes, and snippets.

@pilky
Created April 20, 2012 00:37
Show Gist options
  • Save pilky/2425052 to your computer and use it in GitHub Desktop.
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
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