summaryrefslogtreecommitdiff
path: root/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'ruby')
-rwxr-xr-xruby/binom.rb17
-rwxr-xr-xruby/binom.sh4
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
+