summaryrefslogtreecommitdiff
path: root/stddev
diff options
context:
space:
mode:
Diffstat (limited to 'stddev')
-rwxr-xr-xstddev16
1 files changed, 5 insertions, 11 deletions
diff --git a/stddev b/stddev
index 3bf0270..891c4c9 100755
--- a/stddev
+++ b/stddev
@@ -3,22 +3,16 @@
require 'trollop'
-def usage
- STDERR.write "./stddev [-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 "stddev [-r <d>] < <one number per line>"
opt :round, "Number of digits after decimal point.", :type => :int, :default => -1
end
-
sum = 0.0
i = 0
cached = []
while line=STDIN.gets
- v = line.strip.to_f
+ v = line.to_f
sum += v
cached << v
i +=1
@@ -33,8 +27,8 @@ cached.each { |v|
stddev = Math.sqrt(var)
-if opts[:round] >= 0
- puts stddev.round opts[:round]
+if cfg[:round] >= 0
+ puts stddev.round cfg[:round]
else
puts stddev
end