Module: Combinatorics

Included in:
BernoulliTrials
Defined in:
lib/theory_of_probability.rb

Instance Method Summary collapse

Instance Method Details

#arrangement(n, k) ⇒ Object

Function A(n,k)



25
26
27
28
29
30
31
32
# File 'lib/theory_of_probability.rb', line 25

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) ⇒ Object

Function C(n,k)



14
15
16
17
18
19
20
21
# File 'lib/theory_of_probability.rb', line 14

def combination(n, k)
  f = fact(n, k)
  if n < k or k <= 0
    -1
  else
    f[0] / (f[2] * f[1])
  end
end

#factorial(n) ⇒ Object



8
9
10
# File 'lib/theory_of_probability.rb', line 8

def factorial(n)
  (1..n).inject(:*) || 1
end