diff options
author | Patrick Simianer <p@simianer.de> | 2014-01-29 19:14:08 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-01-29 19:14:08 +0100 |
commit | 68acbb9a0c7967cb90a7e3756fc94fdd8a73d154 (patch) | |
tree | 3b445131dcb203e94473ae1d8aa82a1798585276 /avg | |
parent | 49158e721bfaf6423dca9fc633873218f691c83a (diff) |
make use of nlp_ruby, LICENSE
Diffstat (limited to 'avg')
-rwxr-xr-x | avg | 18 |
1 files changed, 6 insertions, 12 deletions
@@ -3,28 +3,22 @@ require 'trollop' -def usage - STDERR.write "./avg [-r <d>] < <one number per line>\n" - exit 1 -end -usage if not [0,2].include? ARGV.size - -opts = Trollop::options do +cfg = Trollop::options do + banner "avg < <one number per line>" opt :round, "Number of digits after decimal point.", :type => :int, :default => -1 end - sum = 0.0 i = 0 -while line=STDIN.gets - sum += line.strip.to_f +while line = STDIN.gets + sum += line.to_f i +=1 end avg = sum/i.to_f -if opts[:round] >= 0 - puts avg.round opts[:round] +if cfg[:round] >= 0 + puts avg.round cfg[:round] else puts avg end |