Cumulative standard deviation: Difference between revisions
m
→{{header|Raku}}: notate squaring with super-script
Thundergnat (talk | contribs) m (sntax highlighting fixup automation) |
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: notate squaring with super-script) |
||
Line 3,623:
=={{header|Raku}}==
(formerly Perl 6)
Using a closure:
<syntaxhighlight lang="raku" line>sub sd (@a) {
my $mean = @a R/ [+] @a;
sqrt @a R/ [+] map (* - $mean)
}
Line 3,638:
say f $_ for 2, 4, 4, 4, 5, 5, 7, 9;</syntaxhighlight>
Using a state variable (remember that <tt><(x-<x>)²> = <x²> - <x>²</tt>):
<syntaxhighlight lang="raku" line>
sqrt
( .[2] += $x
given state @;
}
say .&stddev
{{out}}
|