diff options
author | Patrick Simianer <p@simianer.de> | 2016-06-24 13:23:03 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2016-06-24 13:23:03 +0200 |
commit | e34007450adcec8441b7a48613c0386defd58fad (patch) | |
tree | d147bc2f7ba1338aae0d64e3ec9d6519fc7f9699 | |
parent | 348bc9e6c0a30844b268fc5dbd431deb65daea9a (diff) |
ruby: binomial
-rwxr-xr-x | ruby/binom.rb | 17 | ||||
-rwxr-xr-x | ruby/binom.sh | 4 |
2 files changed, 21 insertions, 0 deletions
diff --git a/ruby/binom.rb b/ruby/binom.rb new file mode 100755 index 0000000..1a2dc1b --- /dev/null +++ b/ruby/binom.rb @@ -0,0 +1,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) + diff --git a/ruby/binom.sh b/ruby/binom.sh new file mode 100755 index 0000000..fcb73e4 --- /dev/null +++ b/ruby/binom.sh @@ -0,0 +1,4 @@ +#!/bin/zsh + +for i in {0..10}; do ./binom.rb $i 0.1 10; done + |