require 'singleton' class Fact include Singleton def initialize @fact = Hash.new {|h, k| h[k] = k * h[k - 1]} @fact[1] = 1 end def [](n) return 1 if n <= 1 @fact[n] end end class Deck def initialize(seed, size=30) @fact = Fact.instance @seed = seed @size = size end def nCm(n, m) @fact[n].div(@fact[m] * @fact[n - m]) end def zero card = @size - @seed nCm(card, 7).quo(nCm(@size, 7)) end end d = Deck.new(5, 30) puts "%.2f" % (d.zero * 100) d = Deck.new(7, 30) puts "%.2f" % (d.zero * 100)