summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <pks@pks.rocks>2018-03-29 23:22:56 +0200
committerPatrick Simianer <pks@pks.rocks>2018-03-29 23:22:56 +0200
commit93beb31711410183c2d0b1ef7a091272df953a83 (patch)
tree9261acdb71dd32b5ff3d92d7dd61ddb1ec49361d
parent042ec007c64bb168ecf8c9580f8866cc017c4896 (diff)
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
+