RosettaCodeData/Task/Cumulative-standard-deviation/Sidef/cumulative-standard-deviation-2.sidef
2023-07-01 13:44:08 -04:00

10 lines
187 B
Text
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

func stddev(x) {
static(num=0, sum=0, sum2=0)
num++
sqrt(
(sum2 += x**2) / num -
(((sum += x) / num)**2)
)
}
 
%n(2 4 4 4 5 5 7 9).each { say stddev(_) }