For no apparent reason I decided that I wanted to calculate the standard deviation for a column of numbers I'd gathered for somebody. It's been years since I took any statistics courses and I couldn't remember the formula.

I applied what I could remember of the subject, and I wrote the following snippet of code:

do eStem = 1 to Elements

Variance = Variance + ( ( Element.eStem - Mean ) ^ 2 ) / Elements )

end

Standard_Deviation = Variance / 3

do until trunc( Standard_Deviation^2, 15 ) = Variance

Standard_Deviation = .5 * ( Standard_Deviation + ( Variance / Standard_Deviation ) )

end

(Yes, sadly this stupid language doesn't have a square root function, so I had to derive it using Newton's method.)

Only after I'd done this did it occur to me that Excel has a StdDev function that might have worked. I tried that... and it gave me a different answer. Huh?

My immediate assumption was that Excel must be wrong.

Moments later reason set in, and I realized that I had most likely left something out of my equation. After a quick trip to Mister Internet, I revised my program slightly to read:

do eStem = 1 to Elements

Variance = Variance + ( ( Element.eStem - Mean ) ^ 2 ) / ( Elements - 1 ) )

end

Suddenly the world is a joyous place again. I'm not sure why I'm happy that I managed to write a program to replicate what Excel does for me automatically, but it's kind of like whittling a working automobile out of a block of pine. It may not be practical, but at least it's

*yours*.

[Edit: Just for giggles I expanded it to calculate the Nth root, and turned it into a self-contained little module that I can import into any future programs that I write in this language.]