From: "Jesús Gabriel y Galán" Date: 2010-11-05T17:51:43+09:00 Subject: Re: Emacs/putty code help On Fri, Nov 5, 2010 at 7:12 AM, Thierry Ntoh yuh wrote: > Please someone help me with this ruby code on putty/emacs > Thanks > > Write a statistical program in Ruby to: > > a)  Input the name of a data file from the command line arguments. Take a look at ARGV > b)  Input floating-point numbers from the data file. File#readlines and Array#map and String#to_f or Kernel#Float to transform to floats > c)  Calculate and output the mean.  This is the average, or the sum of > the >    values divided by the number of values. sum = array.inject {|total,n| total + n} # this gives you the sum of the values > d)  Calculate and output the median.  This is the value such than half > the >    values are larger and half are smaller.  If you have an even number > of >    values use either middle value or the average of the two middle > values. array.sort[array.size / 2] # will sort the array and take the middle value (or the left side one if even) Hope this sets you on the right track. Let us know how it goes. Jesus.