Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
10
Task/Power-set/Ada/power-set-1.ada
Normal file
10
Task/Power-set/Ada/power-set-1.ada
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package Power_Set is
|
||||
|
||||
type Set is array (Positive range <>) of Positive;
|
||||
Empty_Set: Set(1 .. 0);
|
||||
|
||||
generic
|
||||
with procedure Visit(S: Set);
|
||||
procedure All_Subsets(S: Set); -- calles Visit once for each subset of S
|
||||
|
||||
end Power_Set;
|
||||
20
Task/Power-set/Ada/power-set-2.ada
Normal file
20
Task/Power-set/Ada/power-set-2.ada
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package body Power_Set is
|
||||
|
||||
procedure All_Subsets(S: Set) is
|
||||
|
||||
procedure Visit_Sets(Unmarked: Set; Marked: Set) is
|
||||
Tail: Set := Unmarked(Unmarked'First+1 .. Unmarked'Last);
|
||||
begin
|
||||
if Unmarked = Empty_Set then
|
||||
Visit(Marked);
|
||||
else
|
||||
Visit_Sets(Tail, Marked & Unmarked(Unmarked'First));
|
||||
Visit_Sets(Tail, Marked);
|
||||
end if;
|
||||
end Visit_Sets;
|
||||
|
||||
begin
|
||||
Visit_Sets(S, Empty_Set);
|
||||
end All_Subsets;
|
||||
|
||||
end Power_Set;
|
||||
28
Task/Power-set/Ada/power-set-3.ada
Normal file
28
Task/Power-set/Ada/power-set-3.ada
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
with Ada.Text_IO, Ada.Command_Line, Power_Set;
|
||||
|
||||
procedure Print_Power_Set is
|
||||
|
||||
procedure Print_Set(Items: Power_Set.Set) is
|
||||
First: Boolean := True;
|
||||
begin
|
||||
Ada.Text_IO.Put("{ ");
|
||||
for Item of Items loop
|
||||
if First then
|
||||
First := False; -- no comma needed
|
||||
else
|
||||
Ada.Text_IO.Put(", "); -- comma, to separate the items
|
||||
end if;
|
||||
Ada.Text_IO.Put(Ada.Command_Line.Argument(Item));
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line(" }");
|
||||
end Print_Set;
|
||||
|
||||
procedure Print_All_Subsets is new Power_Set.All_Subsets(Print_Set);
|
||||
|
||||
Set: Power_Set.Set(1 .. Ada.Command_Line.Argument_Count);
|
||||
begin
|
||||
for I in Set'Range loop -- initialize set
|
||||
Set(I) := I;
|
||||
end loop;
|
||||
Print_All_Subsets(Set); -- do the work
|
||||
end;
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
with Ada.Text_IO, Ada.Command_Line;
|
||||
|
||||
procedure Power_Set is
|
||||
|
||||
type List is array (Positive range <>) of Positive;
|
||||
Empty: List(1 .. 0);
|
||||
|
||||
procedure Print_All_Subsets(Set: List; Printable: List:= Empty) is
|
||||
|
||||
procedure Print_Set(Items: List) is
|
||||
First: Boolean := True;
|
||||
begin
|
||||
Ada.Text_IO.Put("{ ");
|
||||
for Item of Items loop
|
||||
if First then
|
||||
First := False; -- no comma needed
|
||||
else
|
||||
Ada.Text_IO.Put(", "); -- comma, to separate the items
|
||||
end if;
|
||||
Ada.Text_IO.Put(Ada.Command_Line.Argument(Item));
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line(" }");
|
||||
end Print_Set;
|
||||
|
||||
Tail: List := Set(Set'First+1 .. Set'Last);
|
||||
|
||||
begin
|
||||
if Set = Empty then
|
||||
Print_Set(Printable);
|
||||
else
|
||||
Print_All_Subsets(Tail, Printable & Set(Set'First));
|
||||
Print_All_Subsets(Tail, Printable);
|
||||
end if;
|
||||
end Print_All_Subsets;
|
||||
|
||||
Set: List(1 .. Ada.Command_Line.Argument_Count);
|
||||
begin
|
||||
for I in Set'Range loop -- initialize set
|
||||
Set(I) := I;
|
||||
end loop;
|
||||
Print_All_Subsets(Set); -- do the work
|
||||
end Power_Set;
|
||||
Loading…
Add table
Add a link
Reference in a new issue