module Silicium::Combinatorics
Public Instance Methods
arrangement(n, k)
click to toggle source
Function A(n,k)
# File lib/theory_of_probability.rb, line 38 def arrangement(n, k) f = fact(n, k) if n < k or k <= 0 -1 else f[0] / f[1] end end
combination(n, k)
click to toggle source
Function C(n,k)
# File lib/theory_of_probability.rb, line 27 def combination(n, k) f = fact(n, k) if n < k or k <= 0 -1 else f[0] / (f[2] * f[1]) end end
fact(n, k)
click to toggle source
Factorial for counting 3 parameters in one run
# File lib/theory_of_probability.rb, line 17 def fact(n, k) res = [1,1,1] if n > 1 fact_n_greater_1(n, k, res) end res end
factorial(n)
click to toggle source
# File lib/theory_of_probability.rb, line 10 def factorial(n) res = (1..n).inject(:*) || 1 res end