Distribution of 0 digits in factorial series: Difference between revisions

m (→‎{{header|Go}}: Added a further libheader.)
Line 97:
10,000 = 0.1730038482
47,332 = 0.1599999958 (stays below 0.16 after this)
</pre>
 
=={{header|Julia}}==
<lang julia>function meanfactorialdigits(N, goal = 0.0)
factoril, proportionsum = big"1", 0.0
for i in 1:N
factoril *= i
d = digits(factoril)
zero_proportion_in_fac = count(x -> x == 0, d) / length(d)
proportionsum += zero_proportion_in_fac
propmean = proportionsum / i
if i > 15 && propmean <= goal
println("The mean proportion dips permanently below $goal at $i.")
break
end
if i == N
println("Mean proportion of zero digits in factorials to $N is ", propmean)
end
end
end
 
@time foreach(meanfactorialdigits, [100, 1000, 10000])
 
@time meanfactorialdigits(50000, 0.16)
</lang>{{out}}
<pre>
Mean proportion of zero digits in factorials to 100 is 0.24675318616743216
Mean proportion of zero digits in factorials to 1000 is 0.20354455110316458
Mean proportion of zero digits in factorials to 10000 is 0.17300384824186707
3.030182 seconds (297.84 k allocations: 1.669 GiB, 0.83% gc time, 0.28% compilation time)
The mean proportion dips permanently below 0.16 at 47332.
179.157788 seconds (3.65 M allocations: 59.696 GiB, 1.11% gc time)
</pre>
 
4,102

edits