Distribution of 0 digits in factorial series: Difference between revisions

Added 11l
(Added 11l)
Line 41:
permanently falls below 0.16. This task took many hours in the Python example, though I wonder if there is a faster
algorithm out there.
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>F facpropzeros(n, verbose = 1B)
V proportions = [0.0] * n
V (fac, psum) = (BigInt(1), 0.0)
L(i) 0 .< n
fac *= i + 1
V d = String(fac)
psum += sum(d.map(x -> Int(x == ‘0’))) / Float(d.len)
proportions[i] = psum / (i + 1)
 
I verbose
print(‘The mean proportion of 0 in factorials from 1 to #. is #..’.format(n, psum / n))
 
R proportions
 
L(n) [100, 1000, 10000]
facpropzeros(n)</lang>
 
{{out}}
<pre>
The mean proportion of 0 in factorials from 1 to 100 is 0.246753186.
The mean proportion of 0 in factorials from 1 to 1000 is 0.203544551.
The mean proportion of 0 in factorials from 1 to 10000 is 0.173003848.
</pre>
 
=={{header|Go}}==
1,463

edits