Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,19 +0,0 @@
|
|||
generic
|
||||
type Result_Type (<>) is limited private;
|
||||
None: Result_Type;
|
||||
with function One(X: Positive) return Result_Type;
|
||||
with function Add(X, Y: Result_Type) return Result_Type
|
||||
is <>;
|
||||
package Generic_Divisors is
|
||||
|
||||
function Process
|
||||
(N: Positive; First: Positive := 1) return Result_Type is
|
||||
(if First**2 > N or First = N then None
|
||||
elsif (N mod First)=0 then
|
||||
(if First = 1 or First*First = N
|
||||
then Add(One(First), Process(N, First+1))
|
||||
else Add(One(First),
|
||||
Add(One((N/First)), Process(N, First+1))))
|
||||
else Process(N, First+1));
|
||||
|
||||
end Generic_Divisors;
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
with Ada.Text_IO, Ada.Containers.Generic_Array_Sort, Generic_Divisors;
|
||||
|
||||
procedure Proper_Divisors is
|
||||
|
||||
begin
|
||||
-- show the proper divisors of the numbers 1 to 10 inclusive.
|
||||
declare
|
||||
type Pos_Arr is array(Positive range <>) of Positive;
|
||||
subtype Single_Pos_Arr is Pos_Arr(1 .. 1);
|
||||
Empty: Pos_Arr(1 .. 0);
|
||||
|
||||
function Arr(P: Positive) return Single_Pos_Arr is ((others => P));
|
||||
|
||||
package Divisor_List is new Generic_Divisors
|
||||
(Result_Type => Pos_Arr, None => Empty, One => Arr, Add => "&");
|
||||
|
||||
procedure Sort is new Ada.Containers.Generic_Array_Sort
|
||||
(Positive, Positive, Pos_Arr);
|
||||
begin
|
||||
for I in 1 .. 10 loop
|
||||
declare
|
||||
List: Pos_Arr := Divisor_List.Process(I);
|
||||
begin
|
||||
Ada.Text_IO.Put
|
||||
(Positive'Image(I) & " has" &
|
||||
Natural'Image(List'Length) & " proper divisors:");
|
||||
Sort(List);
|
||||
for Item of List loop
|
||||
Ada.Text_IO.Put(Positive'Image(Item));
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
end;
|
||||
end loop;
|
||||
end;
|
||||
|
||||
-- find a number 1 .. 20,000 with the most proper divisors
|
||||
declare
|
||||
Number: Positive := 1;
|
||||
Number_Count: Natural := 0;
|
||||
Current_Count: Natural;
|
||||
|
||||
function Cnt(P: Positive) return Positive is (1);
|
||||
|
||||
package Divisor_Count is new Generic_Divisors
|
||||
(Result_Type => Natural, None => 0, One => Cnt, Add => "+");
|
||||
|
||||
begin
|
||||
for Current in 1 .. 20_000 loop
|
||||
Current_Count := Divisor_Count.Process(Current);
|
||||
if Current_Count > Number_Count then
|
||||
Number := Current;
|
||||
Number_Count := Current_Count;
|
||||
end if;
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line
|
||||
(Positive'Image(Number) & " has the maximum number of" &
|
||||
Natural'Image(Number_Count) & " proper divisors.");
|
||||
end;
|
||||
end Proper_Divisors;
|
||||
Loading…
Add table
Add a link
Reference in a new issue