Distribution of 0 digits in factorial series: Difference between revisions
Distribution of 0 digits in factorial series (view source)
Revision as of 21:09, 2 April 2023
, 1 year ago→{{header|Ruby}}: Add Ruby
Drkameleon (talk | contribs) (added Arturo) |
(→{{header|Ruby}}: Add Ruby) |
||
Line 1,247:
Mean proportion of zero digits in factorials to 10000 is 0.1730038482. (149ms)
The mean proportion dips permanently below 0.16 at 47332. (4485ms)
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">[100, 1000, 10_000].each do |n|
v = 1
total_proportion = (1..n).sum do |k|
v *= k
digits = v.digits
Rational(digits.count(0), digits.size)
end
puts "The mean proportion of 0 in factorials from 1 to #{n} is #{(total_proportion/n).to_f}."
end</syntaxhighlight>
{{out}}
<pre>The mean proportion of 0 in factorials from 1 to 100 is 0.24675318616743222.
The mean proportion of 0 in factorials from 1 to 1000 is 0.20354455110316463.
The mean proportion of 0 in factorials from 1 to 10000 is 0.17300384824186604.
</pre>
=={{header|Sidef}}==
Line 1,271 ⟶ 1,286:
0.173003848241866053180036642893070615681027880906
</pre>
=={{header|Wren}}==
===Brute force===
|