Distribution of 0 digits in factorial series: Difference between revisions
Distribution of 0 digits in factorial series (view source)
Revision as of 19:24, 10 June 2021
, 2 years ago→{{header|Raku}}: Add a Raku example
mNo edit summary |
Thundergnat (talk | contribs) (→{{header|Raku}}: Add a Raku example) |
||
Line 71:
The mean proportion of 0 in factorials from 1 to 10000 is 0.17300384824186707.
The mean proportion dips permanently below 0.16 at 47332.
</pre>
=={{header|Raku}}==
Works, but depressingly slow for 10000.
<lang perl6>sub postfix:<!> (Int $n) { ( constant factorial = 1, 1, |[\*] 2..* )[$n] }
sink 10000!; # prime the iterator to allow multithreading
sub zs ($n) { ( constant zero-share = (^Inf).race(:32batch).map: { (.!.comb.Bag){'0'} / .!.chars } )[$n] }
.say for (
100
,1000
,10000
).map: -> \n { "{n}: {([+] (^n).map: *.&zs) / n}" }</lang>
{{out}}
<pre>100: 0.24485445199021696
1000: 0.20336075048011162
10000: 0.17298757510670162
</pre>
|