summaryrefslogtreecommitdiff
path: root/ruby
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2017-07-04 21:09:27 +0200
committerPatrick Simianer <p@simianer.de>2017-07-04 21:09:27 +0200
commit740f82a87a6f5573e80b3263f540efa831e05100 (patch)
treed32081c78098130c494d15d6854cf3169d3c56c0 /ruby
parentf4fca383b61034ea7b0432d3ef1c2c00174658d4 (diff)
multinom
Diffstat (limited to 'ruby')
-rwxr-xr-xruby/multinom.rb21
-rw-r--r--ruby/multinom.sh4
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"
+