Anonymous user
Distribution of 0 digits in factorial series: Difference between revisions
Distribution of 0 digits in factorial series (view source)
Revision as of 07:21, 13 June 2021
, 3 years ago→{{header|Pascal}}: delete unused arrays, reorder, more comments
m (→{{header|REXX}}: reworded a comment.) |
m (→{{header|Pascal}}: delete unused arrays, reorder, more comments) |
||
Line 206:
CountOfZero : array[0..999] of byte;
SumOfRatio :array[0..LIMIT] of extended;
// for testing
Begin▼
write(pMul[lmt]);▼
For lmt := lmt-1 downto 0 do▼
write(Format('%.9d',[pMul[lmt]]));▼
writeln;▼
end;▼
procedure InitCoZ;
//Init Lookup table for 3 digits
var
begin
fillchar(CountOfZero,SizeOf(CountOfZero),#0);
CountOfZero[0] := 3; //000
For
Begin
CountOfZero[
CountOfZero[10*
CountOfZero[100*
repeat
CountOfZero[
CountOfZero[10*
CountOfZero[10*(
inc(
until
end;
end;
Line 243 ⟶ 252:
end;
//count zeros in Base 1,000,000,000 number
▲Begin
▲ write(pMul[lmt]);
▲ For lmt := lmt-1 downto 0 do
▲ write(Format('%.9d',[pMul[lmt]]));
▲ writeln;
▲end;
▲function CheckForZero(pMul:tpMul;Lmt :NativeInt):NativeUint;
var
q,r : LongWord;
i : NativeInt;
begin
result := 0;
For i :=
Begin
q := pMul[i];
r := q DIV 1000;
result +=CountOfZero[q-1000*r];//q-1000*r == q mod 1000
q := r;
r := q DIV 1000;
Line 272 ⟶ 271:
result +=CountOfZero[q-1000*r];
end;
//special case first digits no leading '0'
q := pMul[lmt];
while q >= 1000 do
Line 279:
q := r;
end;
q
inc(result);▼
end;
end;
function GetCoD(pMul:tpMul;Lmt :NativeInt):NativeUint;
//count of decimal digits
var
i : longWord;
Line 305 ⟶ 304:
inc(result);
end;
procedure DoChecks(pMul:tpMul;Lmt,i :NativeInt);
//(extended(1.0)* makes TIO.RUN faster // only using FPU?
end;
function MulByI(pMul:tpMul;UL,i :NativeInt):NativeInt;
var
prod : Uint64;
j : nativeInt;
carry : LongWord;
begin
result := UL;
For j := 0 to result do
end;
Begin
end;
Line 311 ⟶ 339:
MulArr : tMul;
pMul : tpMul;
begin
i := getFactorialDecDigits(n) DIV 9 +10;
Line 321 ⟶ 348:
i := 1;
repeat
DoChecks(pMul,UL,i);
▲ Begin
▲ prod := i*pMul[j]+Carry;
▲ Carry := prod Div LongWordDec;
▲ pMul[j] := Prod - Carry*LongWordDec;
▲ end;
▲ IF Carry <> 0 then
▲ Begin
▲ inc(Ul);
▲ pMul[UL]:= Carry;
▲ End;
▲ SumOfRatio[i] := SumOfRatio[i-1] + CoZ_Fac[i]/CoD_Fac[i];
inc(i);
until i> n;
Line 348 ⟶ 361:
writeln(i:8,SumOfRatio[i]/i:18:15);
end;
var
i : integer;
Line 353 ⟶ 367:
InitCoZ;
SumOfRatio[0]:= 0;
▲ CoD_Fac[0]:= 0;
getFactorialExact(LIMIT);
Out_(100);
Line 371 ⟶ 383:
end.</lang>
{{out}}
<pre> 100 0.246753186167432▼
▲ 100 0.246753186167432
1000 0.203544551103165
10000 0.173003848241866
50000 0.159620054602269
First ratio < 0.16 47332 0.15999999579985665
Real time:
=={{header|Python}}==
|