Hi,

I have a piece of code which I think should be working, but it doesn't.

def standard_dev(a, mean)
   Math.sqrt((a.inject(0.0){|v,r| r += (v-mean)*(v-mean) })/a.length)
end

computes results that don't make sense and differ from the values 
computed by this code:

def standard_dev(a, mean)
   r = 0.0
   a.each{|v| r += (v-mean)*(v-mean) }
   Math.sqrt(r/a.length)
end

I think the two should be different. Am I missing something?

-- stefan