Distribution of 0 digits in factorial series: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added a stub for REXX.) |
(→{{header|REXX}}: added the computer programming language REXX.) |
||
Line 73: | Line 73: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program computes the mean of the proportion of "0" digits a series of factorials.*/ |
|||
<lang rexx></lang> |
|||
parse arg $ /*obtain optional arguments from the CL*/ |
|||
output |
|||
if $='' | $="," then $= 100 1000 10000 /*not specified? Then use the default.*/ |
|||
⚫ | |||
#= words($) /*the number of ranges to be used here.*/ |
|||
numeric digits 100 /*increase dec. digs, but only to 100. */ |
|||
big= word($, #); != 1 /*obtain the largest number in ranges. */ |
|||
do i=1 for big /*calculate biggest ! using 100 digs.*/ |
|||
!= ! * i /*calculate the factorial of BIG. */ |
|||
end /*i*/ |
|||
if pos('E', !)>0 then do /*if its in exponential format, get EXP*/ |
|||
parse var ! 'E' x /*parse the exponent from the number. */ |
|||
numeric digits x+1 /*set the decimal digits to X plus 1.*/ |
|||
end /* [↑] the +1 is for the dec. point.*/ |
|||
title= ' mean proportion of zeros in the (decimal) factorial products for N' |
|||
say ' N │'center(title, 80) /*display the title for the output. */ |
|||
say '───────────┼'center("" , 80, '─') /* " a sep " " " */ |
|||
do j=1 for #; n= word($, j) /*calculate some factorial ranges. */ |
|||
p= 0dist(n) /* " the proportion of zeros. */ |
|||
say center( commas(n), 11)'│' left(p/n, 75)... /*display the results for above range. */ |
|||
end /*j*/ |
|||
say '───────────┴'center("" , 80, '─') /*display a foot sep for the output. */ |
|||
exit 0 /*stick a fork in it, we're all done. */ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ? |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
0dist: procedure; parse arg target; != 1; y= 0 |
|||
do k=1 for target; != ! * k; z= countstr(0, !); y= y+ z/length(!) |
|||
end /*k*/ |
|||
return y</lang> |
|||
{{out|output|text= when using the default inputs:}} |
|||
⚫ | |||
N │ mean proportion of zeros in the (decimal) factorial products for N |
|||
───────────┼──────────────────────────────────────────────────────────────────────────────── |
|||
100 │ 0.2467531861674322177784158871973526991129407033266153063813195937196095976... |
|||
1,000 │ 0.2035445511031646356400438031711455302985741167890402203486699704599684047... |
|||
10,000 │ 0.1730038482418660531800366428930706156810278809057883361518852958446868172... |
|||
───────────┴──────────────────────────────────────────────────────────────────────────────── |
|||
</pre> |
</pre> |
||