#!/usr/bin/ruby

#
## https://rosettacode.org/wiki/Standard_deviation
#

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(_) }