Power set: Difference between revisions

No edit summary
Line 234:
with Ada.Text_IO, Ada.Command_Line;
use Ada.Text_IO, Ada.Command_Line;
 
procedure powerset is
procedure print_subset (set : natural) is
-- each i'th binary digit of "set" indicates if the i'th integer belongs to "set" or not.
k : natural := set;
first : boolean := true;
begin
Put ("{");
for i in 1..Argument_Count loop
if k mod 2 = 1 then
if first then
first := false;
else
Put (",");
end if;
Put (Argument (i));
end if;
k := k / 2; -- we go to the next bit of "set"
end loop;
Put_Line("}");
end print_subset;
begin
for iset in 0..2**Argument_Count-1 loop
declare
print_subset (i);
k : natural := set;
end loop;
first : boolean := true;
begin
Put ("{");
for i in 1..Argument_Count loop
if k mod 2 = 1 then
Put ((if first then Put"" else ",") & (Argument (i));
first := false;
end if;
k := k / 2; -- we go to the next bit of "set"
end loop;
Put_Line("}");
end loop;
end powerset;
</lang>
Anonymous user