Statistics/Basic: Difference between revisions
Content added Content deleted
(→{{header|Python}}: bug fixes) |
(→{{header|Perl 6}}: arguably simpler version) |
||
Line 1,197: | Line 1,197: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
<lang perl6> |
<lang perl6>for 100, 1_000, 10_000 -> $N { |
||
say "size: $N"; |
|||
my |
my @data = rand xx $N; |
||
my $ |
printf "mean: %f\n", my $mean = $N R/ [+] @data; |
||
⚫ | |||
my @hist = 0 xx 10; |
|||
my $variance = $mean**2 R- $N R/ [+] @data »**» 2; |
|||
for ^$n { |
|||
for sort *.key, @data.classify( (10 * *).Int / 10 ) { |
|||
my $r = rand; |
|||
⚫ | |||
$sum += $r; |
|||
$sum2 += $r ** 2; |
|||
++@hist[10 * $r]; |
|||
} |
} |
||
⚫ | |||
my $mean = $sum / $n; |
|||
my $stddev = sqrt($sum2 / $n - $mean * $mean); |
|||
say "size: $n"; |
|||
say "mean: $mean"; |
|||
⚫ | |||
for @hist.kv -> $i, $bin { |
|||
⚫ | |||
} |
|||
say "(elapsed: {time - $then})"; |
|||
⚫ | |||
} |
|||
# This doesn't terminate, so ^C when you get bored. |
|||
for 100, 1_000, 10_000 ... * -> $n { |
|||
generate_statistics $n; |
|||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
Line 1,239: | Line 1,222: | ||
0.8 ====================================================================== |
0.8 ====================================================================== |
||
0.9 ============================================= |
0.9 ============================================= |
||
(elapsed: 0.023430109024047852) |
|||
size: 1000 |
size: 1000 |
||
Line 1,254: | Line 1,236: | ||
0.8 ============================================== |
0.8 ============================================== |
||
0.9 ======================================================== |
0.9 ======================================================== |
||
(elapsed: 0.083790063858032227) |
|||
size: 10000 |
size: 10000 |
||
Line 1,269: | Line 1,250: | ||
0.8 ==================================================== |
0.8 ==================================================== |
||
0.9 ================================================== |
0.9 ================================================== |
||
(elapsed: 0.5168910026550293) |
|||
size: 100000 |
size: 100000 |
||
Line 1,300: | Line 1,280: | ||
0.9 ================================================= |
0.9 ================================================= |
||
(elapsed: 47.345431089401245)</pre> |
(elapsed: 47.345431089401245)</pre> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
The following has no limit on the number of samples. The 'statistics' function accepts an executable body 'Prg', which it calls repeatedly to get the samples. |
The following has no limit on the number of samples. The 'statistics' function accepts an executable body 'Prg', which it calls repeatedly to get the samples. |