matthew.moss.coder
3/28/2006 12:39:00 AM
I'm not sure how that would work.... you're re-reading the input stream twice.
Anyway, here's my version. I could compact it more, but I won't try
confusing you too much all at once. =)
figures = STDIN.read.split("\n").map { |x| x.to_f }
sum = figures.inject { |s, x| s + x }
average = sum / figures.size
high = figures.select { |x| x > average }
puts "Average: #{average}"
puts "Count greater than average: #{high.size}"