Distribution of 0 digits in factorial series: Difference between revisions
Distribution of 0 digits in factorial series (view source)
Revision as of 07:39, 5 October 2021
, 2 years ago→{{header|11l}}: Base 1000 version
Alextretyak (talk | contribs) (Added 11l) |
Alextretyak (talk | contribs) (→{{header|11l}}: Base 1000 version) |
||
Line 67:
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>
=== Base 1000 version ===
<lang 11l>F zinit()
V zc = [0] * 999
L(x) 1..9
zc[x - 1] = 2
zc[10 * x - 1] = 2
zc[100 * x - 1] = 2
L(y) (10.<100).step(10)
zc[y + x - 1] = 1
zc[10 * y + x - 1] = 1
zc[10 * (y + x) - 1] = 1
R zc
F meanfactorialdigits()
V zc = zinit()
V rfs = [1]
V (total, trail, first) = (0.0, 1, 0)
L(f) 2 .< 50000
V (carry, d999, zeroes) = (0, 0, (trail - 1) * 3)
V (j, l) = (trail, rfs.len)
L j <= l | carry != 0
I j <= l
carry = rfs[j - 1] * f + carry
d999 = carry % 1000
I j <= l
rfs[j - 1] = d999
E
rfs.append(d999)
zeroes += I d999 == 0 {3} E zc[d999 - 1]
carry I/= 1000
j++
L rfs[trail - 1] == 0
trail++
d999 = rfs.last
d999 = I d999 >= 100 {0} E I d999 < 10 {2} E 1
zeroes -= d999
V digits = rfs.len * 3 - d999
total += Float(zeroes) / digits
V ratio = total / f
I f C [100, 1000, 10000]
print(‘The mean proportion of zero digits in factorials to #. is #.’.format(f, ratio))
I ratio >= 0.16
first = 0
E I first == 0
first = f
print(‘The mean proportion dips permanently below 0.16 at ’first‘.’)
meanfactorialdigits()</lang>
{{out}}
<pre>
The mean proportion of zero digits in factorials to 100 is 0.246753186
The mean proportion of zero digits in factorials to 1000 is 0.203544551
The mean proportion of zero digits in factorials to 10000 is 0.173003848
The mean proportion dips permanently below 0.16 at 47332.
</pre>
|