text
stringlengths 0
234
|
|---|
end AddElemToAllLists;
|
-- adds two lists of lists together
|
function ConcatList (LL1, LL2 : Partition_Type) return Partition_Type
|
is
|
RetLL : Partition_Type (0 .. (LL1'Length + LL2'Length - 1));
|
LL1First : Partition := LL1 (0);
|
LL2First : Partition := LL2 (0);
|
begin
|
-- checks emptinesses of lists
|
if ((LL1First (0) = -1) and (LL2First (0) = -1)) then
|
return LL1;
|
elsif (LL1First (0) = -1) then
|
return LL2;
|
elsif (LL2First (0) = -1) then
|
return LL1;
|
else
|
-- puts in LL1
|
for I in LL1'Range loop
|
RetLL (I) := LL1 (I);
|
end loop;
|
-- puts in LL2
|
for I in LL2'Range loop
|
RetLL (I + LL1'Length) := LL2(I);
|
end loop;
|
end if;
|
return RetLL;
|
end ConcatList;
|
-- compiles a list of partitions
|
function PrimePartition (N, K, J : Integer) return Partition_Type
|
is
|
Empty_Partition : Partition := (others => -1);
|
Empty_Partition_Type : Partition_Type (0 .. 0) := (0 => Empty_Partition);
|
Primes : Sieve_Type := SievePrimes (N, K);
|
IPrime : Integer := 0;
|
NPrimePartition : Partition := (0 => N, others => -1);
|
NPrimeList : Partition_Type (0 .. 0) := (0 => NPrimePartition);
|
begin
|
-- gets the lowest prime between K and N
|
for I in Primes'Range loop
|
if (Primes (I)) then
|
IPrime := I;
|
exit when True;
|
end if;
|
end loop;
|
-- if no primes then return empty list
|
if (IPrime = 0) then
|
return Empty_Partition_Type;
|
end if;
|
-- if bad input then return empty list
|
if ((N <= 1) or (N < K)) then
|
return Empty_Partition_Type;
|
-- if n is prime and first call with n as n
|
elsif ((IsPrime (N)) and (J = 1)) then
|
-- add the prime to the sub partitions returned concatenated with partitions using the same n concatenated with n
|
return ConcatList ((ConcatList ((AddElemToAllLists ((PrimePartition ((N - IPrime), (IPrime + 1), 1)), IPrime)), (primePartition (N, (IPrime + 1), (J + 1))))), NPrimeList);
|
else
|
-- same as above but don't concat n
|
return ConcatList ((AddElemToAllLists ((PrimePartition ((N - IPrime), (IPrime + 1), 1)), IPrime)), (primePartition (N, (IPrime + 1), (J + 1))));
|
end if;
|
end PrimePartition;
|
-- prints a list of partitions in the desired format
|
procedure PrintLL (LL : Partition_Type)
|
is
|
begin
|
for I in LL'Range loop
|
declare
|
L : Partition := (LL (I));
|
begin
|
for J in L'Range loop
|
if ((L (J)) = -1) then
|
exit;
|
else
|
Ada.Text_IO.Put(Integer'Image (L (J)) & " ");
|
end if;
|
end loop;
|
Function Definition: procedure words is
|
Function Body: package ASU renames Ada.Strings.Unbounded;
|
package ACL renames Ada.Command_Line;
|
package ATI renames Ada.Text_IO;
|
package WL renames Word_Lists;
|
File_Name: ASU.Unbounded_String;
|
Fich: Ada.Text_IO.File_Type;
|
List: WL.Word_List_Type;
|
Word: ASU.Unbounded_String;
|
Count: Natural;
|
procedure Print_Menu is
|
--Imprime el menú interactivo
|
begin
|
ATI.New_Line;
|
ATI.Put_Line("Options");
|
ATI.Put_Line("1 Add Word");
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.