summaryrefslogtreecommitdiff
path: root/cma
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2018-04-11 13:15:30 +0000
committerPatrick Simianer <p@simianer.de>2018-04-11 13:15:30 +0000
commitc4bf03972a71cd3507aa8ef9c3a0ca37a01ace77 (patch)
tree0e1e7f53e9383a67e44f62490e648e0d6084d687 /cma
parent3562d3042ee2b95855e976870221a35a60001834 (diff)
parent2920497fb155cd7285a77c1c01f6d424d8fd30e9 (diff)
Merge branch 'master' of https://github.com/pks/nlp_scripts
Diffstat (limited to 'cma')
-rwxr-xr-xcma22
1 files changed, 22 insertions, 0 deletions
diff --git a/cma b/cma
new file mode 100755
index 0000000..9133a0d
--- /dev/null
+++ b/cma
@@ -0,0 +1,22 @@
+#!/usr/bin/env ruby
+
+require 'trollop'
+
+conf = Trollop::options do
+ banner "cma < <one number per line>"
+ opt :round, "Number of digits after decimal point.", :type => :int, :default => -1
+end
+
+cma = 0.0
+i = 0
+while line = STDIN.gets
+ x = line.to_f
+ cma = cma + ((x - cma)/(i+1))
+ i +=1
+ if conf[:round] >= 0
+ puts cma.round conf[:round]
+ else
+ puts cma
+ end
+end
+