On Thu, 26 Apr 2007 00:16:01 +0900, Andrei Ursan wrote:

> This is what i was trying to do :

This is something I can read :-)
You want to calculate the arithmetic mean of some numbers.

I'd do the following as a basic attempt without any
bells and whistles:

1 lines = $stdin.readlines
2 numbers = lines.collect { |line| line.to_f }
3 total = numbers.inject(0) { |sum, x| sum + x }
4 mean = total / numbers.size
5 puts("Arithmetic mean: #{mean}")

You could insert some filter for non-parseable input
between 1 and 2, skip over the unnecessary calculations
in case there was no input with a conditional between 2 and 3,
show the entered values like you did between 4 and 5.

There's no need to "preallocate" arrays, as you can return
any object in ruby. You can even return multiple objects and
access them immediately or through the wrapping array.

HTH,
s.