blob: 464771039456ab4137abd837913ef8012c18acc0 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 | #!/usr/bin/env ruby
require 'optimist'
conf = Optimist::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
  STDOUT.flush
end
 |