diff options
-rwxr-xr-x | ruby/multinom.rb | 21 | ||||
-rw-r--r-- | ruby/multinom.sh | 4 |
2 files changed, 25 insertions, 0 deletions
diff --git a/ruby/multinom.rb b/ruby/multinom.rb new file mode 100755 index 0000000..afee4b7 --- /dev/null +++ b/ruby/multinom.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby + +def fak n + r = 1 + (1).upto(n) { |i| r = r*i } + return r +end + +def multinom n, ks, ps + b = fak(n) + prod = 1 + ks.each { |k| prod = prod*fak(k) } + b = b/prod + ps.each_with_index { |p,j| + b = b*p**ks[j] + } + return b +end + +puts multinom(ARGV[0].to_f, ARGV[1].split.map{|i| i.to_f}, ARGV[2].split.map{|i| i.to_f}) + diff --git a/ruby/multinom.sh b/ruby/multinom.sh new file mode 100644 index 0000000..f78d4d5 --- /dev/null +++ b/ruby/multinom.sh @@ -0,0 +1,4 @@ +#!/bin/zsh -x + +./multinom.rb 10 "0 10" "0.1 0.9" + |