1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/env ruby def binom n, k prod = 1 (1..k).each { |j| prod *= (n+1-j)/j } return prod end def bdist k, p, n binom(n, k)*(p**k)*(1-p)**(n-k) end puts bdist(ARGV[0].to_f, ARGV[1].to_f, ARGV[2].to_f)