Distribution of 0 digits in factorial series

From Rosetta Code
Revision as of 03:07, 10 June 2021 by Wherrera (talk | contribs) (Create page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Distribution of 0 digits in factorial series is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Large Factorials and the Distribution of '0' in base 10 digits.

About the task

We can see that some features of factorial numbers (the series of numbers 1!, 2!, 3!, ...) come about because such numbers are the product of a series of counting numbers, and so those products have predictable factors. For example, all factorials above 1! are even numbers, since they have 2 as a factor. Similarly, all factorials from 5! up end in a 0, because they have 5 and 2 as factors, and thus have 10 as a factor. In fact, the factorial integers add another 0 at the end of the factorial for every step of 5 upward: 5! = 120, 10! = 3628800, 15! = 1307674368000, 16! = 20922789888000 and so on.

Because factorial numbers, which quickly become quite large, continue to have another terminal 0 on the right hand side of the number for every 5 increase in the factorial base number, one might think that the proportion of zeros in a base 10 factorial number might be close to 1/5. However, though the factorial products add another terminating 0 every 5, as the numbers become quite large, the number of digits in the factorial product expands exponentially, and the number above the terminating zeros tends toward 10% of each digit from 0 to 1, as the factorial becomes larger. Thus, as the factorials become larger, the proportion of 0 digits in the factorial products shifts slowly from around 1/5 toward 1/10, since the number of terminating zeros in n! increases only in proportion to n, whereas the number of digits of n in base 10 increases exponentially.

The task

Create a function to calculate the total fraction of zero digits in the aggregate digits of all factorials from 1 to N. The proportion of 0 digits in base 10 should be calculated using the number as printed as a base 10 integer.

Example: for 1 to 6 we have 1!, 2!, 3!, 4!, 5!, 6!, or (1, 2, 3, 24, 120, 720), so (2 zero digits) / (8 total digits) = 0.25.

Example: for 1 to 25 we the aggregate proportion of 0 digits in the aggregated factorial products is 0.26787.

Do this task for 1 to N where N is in (100, 1000, and 10000), so, compute the aggregate proportion of 0 digits in the aggregate of all digits for factorials from 1 to 100, 1 to 1000, and 1 to 10000.

Stretch task

Find the N in 10000 < N < 50000 where the proportion of 0 digits in the aggregated factorial products from 1 to N permanently falls below 0.16.