Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,7 +1,7 @@
|
|||
100 REM Bell numbers
|
||||
110 LET MaxN = 14
|
||||
120 OPTION BASE 0
|
||||
130 DIM A(13) ! i.e. DIM A(MaxN - 1), ANSI BASIC does not allow expressions in the bound arguments.
|
||||
110 OPTION BASE 0
|
||||
120 DIM A(13)
|
||||
130 LET MaxN = UBOUND(A) + 1
|
||||
140 FOR I = 0 TO MaxN - 1
|
||||
150 LET A(I) = 0
|
||||
160 NEXT I
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
procedure Main is
|
||||
type Bell_Triangle is array(Positive range <>, Positive range <>) of Natural;
|
||||
|
||||
|
||||
procedure Print_Rows (Row : in Positive; Triangle : in Bell_Triangle) is
|
||||
begin
|
||||
if Row in Triangle'Range(1) then
|
||||
for I in Triangle'First(1) .. Row loop
|
||||
Put_Line (Triangle (I, 1)'Image);
|
||||
end loop;
|
||||
end if;
|
||||
end Print_Rows;
|
||||
|
||||
procedure Print_Triangle (Num : in Positive; Triangle : in Bell_Triangle) is
|
||||
begin
|
||||
if Num in Triangle'Range then
|
||||
for I in Triangle'First(1) .. Num loop
|
||||
for J in Triangle'First(2) .. Num loop
|
||||
if Triangle (I, J) /= 0 then
|
||||
Put (Triangle (I, J)'Image);
|
||||
end if;
|
||||
end loop;
|
||||
New_Line;
|
||||
end loop;
|
||||
end if;
|
||||
end Print_Triangle;
|
||||
|
||||
procedure Bell_Numbers is
|
||||
Triangle : Bell_Triangle(1..15, 1..15) := (Others => (Others => 0));
|
||||
Temp : Positive := 1;
|
||||
begin
|
||||
|
||||
Triangle (1, 1) := 1;
|
||||
|
||||
for I in Triangle'First(1) + 1 .. Triangle'Last(1) loop
|
||||
Triangle (I, 1) := Temp;
|
||||
|
||||
for J in Triangle'First(2) .. Triangle'Last(2) - 1 loop
|
||||
if Triangle (I - 1, J) /= 0 then
|
||||
Triangle (I, J + 1) := Triangle (I, J) + Triangle (I - 1, J);
|
||||
else
|
||||
Temp := Triangle (I, J);
|
||||
exit;
|
||||
end if;
|
||||
end loop;
|
||||
end loop;
|
||||
|
||||
Put_Line ("First 15 Bell numbers:");
|
||||
Print_Rows (15, Triangle);
|
||||
|
||||
New_Line;
|
||||
|
||||
Put_Line ("First 10 rows of the Bell triangle:");
|
||||
Print_Triangle (10, Triangle);
|
||||
end Bell_Numbers;
|
||||
begin
|
||||
Bell_Numbers;
|
||||
end Main;
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
program BellNumbers;
|
||||
{$Ifdef FPC}
|
||||
{$optimization on,all}
|
||||
{$ElseIf}
|
||||
{Apptype console}
|
||||
{$EndIf}
|
||||
uses
|
||||
sysutils,gmp;
|
||||
var
|
||||
T0 :TDateTime;
|
||||
procedure BellNumbersUint64(OnlyBellNumbers:Boolean);
|
||||
var
|
||||
BList : array[0..24] of Uint64;
|
||||
BellNum : Uint64;
|
||||
BListLenght,i :nativeUInt;
|
||||
begin
|
||||
IF OnlyBellNUmbers then
|
||||
Begin
|
||||
writeln('Bell triangles ');
|
||||
writeln(' 1 = 1');
|
||||
end
|
||||
else
|
||||
Begin
|
||||
writeln('Bell numbers');
|
||||
writeln(' 1 = 1');
|
||||
writeln(' 2 = 1');
|
||||
end;
|
||||
|
||||
BList[0]:= 1;
|
||||
BListLenght := 1;
|
||||
BellNum := 1;
|
||||
repeat
|
||||
// For i := BListLenght downto 1 do BList[i] := BList[i-1]; or
|
||||
move(Blist[0],Blist[1],BListLenght*SizeOf(Blist[0]));
|
||||
BList[0] := BellNum;
|
||||
For i := 1 to BListLenght do
|
||||
Begin
|
||||
BellNum += BList[i];
|
||||
BList[i] := BellNum;
|
||||
end;
|
||||
|
||||
// Output
|
||||
IF OnlyBellNUmbers then
|
||||
Begin
|
||||
IF BListLenght<=9 then
|
||||
Begin
|
||||
write(BListLenght+1:3,' = ');
|
||||
For i := 0 to BListLenght do
|
||||
write(BList[i]:7);
|
||||
writeln;
|
||||
end
|
||||
ELSE
|
||||
BREAK;
|
||||
end
|
||||
else
|
||||
writeln(BListLenght+2:3,' = ',BellNum);
|
||||
|
||||
inc(BListLenght);
|
||||
until BListLenght >= 25;
|
||||
writeln;
|
||||
end;
|
||||
|
||||
procedure BellNumbersMPInteger;
|
||||
const
|
||||
MaxIndex = 5000;//must be > 0
|
||||
var
|
||||
//MPInteger as alternative to mpz_t -> selfcleaning
|
||||
BList : array[0..MaxIndex] of MPInteger;
|
||||
BellNum : MPInteger;
|
||||
BListLenght,i :nativeUInt;
|
||||
BellNumStr : AnsiString;
|
||||
Begin
|
||||
BellNumStr := '';
|
||||
z_init(BellNum);
|
||||
z_ui_pow_ui(BellNum,10,32767);
|
||||
BListLenght := z_size(BellNum);
|
||||
writeln('init length ',BListLenght);
|
||||
For i := 0 to MaxIndex do
|
||||
Begin
|
||||
// z_init2_set(BList[i],BListLenght);
|
||||
z_add_ui( BList[i],i);
|
||||
end;
|
||||
writeln('init length ',z_size(BList[0]));
|
||||
|
||||
T0 := now;
|
||||
BListLenght := 1;
|
||||
z_set_ui(BList[0],1);
|
||||
z_set_ui(BellNum,1);
|
||||
repeat
|
||||
//Move does not fit moving interfaces // call fpc_intf_assign
|
||||
For i := BListLenght downto 1 do BList[i] := BList[i-1];
|
||||
z_set(BList[0],BellNum);
|
||||
For i := 1 to BListLenght do
|
||||
Begin
|
||||
BellNum := z_add(BellNum,BList[i]);
|
||||
z_set(BList[i],BellNum);
|
||||
end;
|
||||
inc(BListLenght);
|
||||
if (BListLenght+1) MOD 100 = 0 then
|
||||
Begin
|
||||
BellNumStr:= z_get_str(10,BellNum);
|
||||
//z_sizeinbase (BellNum, 10) is not exact :-(
|
||||
write('Bell(',(IntToStr(BListLenght)):6,') has ',
|
||||
(IntToStr(Length(BellNumStr))):6,' decimal digits');
|
||||
writeln(FormatDateTime(' NN:SS.ZZZ',now-T0),'s');
|
||||
end;
|
||||
until BListLenght>=MaxIndex;
|
||||
BellNumStr:= z_get_str(10,BellNum);
|
||||
writeln(BListLenght:6,'.th ',Length(BellNumStr):8);
|
||||
|
||||
//clean up ;-)
|
||||
BellNumStr := '';
|
||||
z_clear(BellNum);
|
||||
For i := MaxIndex downto 0 do
|
||||
z_clear(BList[i]);
|
||||
end;
|
||||
|
||||
BEGIN
|
||||
BellNumbersUint64(True);BellNumbersUint64(False);
|
||||
BellNumbersMPInteger;
|
||||
END.
|
||||
Loading…
Add table
Add a link
Reference in a new issue