-- combinations.ads -- n is for n things n! / ((n-m)! m!) combinations -- m is for m at a time -- Vn must be the n items, unchanged by combinations -- Vm must be of size m items, the returned combination each call -- First must be true the first call, then set to false internally -- Last is false if more combinations to come. -- Last is True for the final combination -- instantiate package: -- package my_comb is new combinations(10, integer, integer_vector); -- then -- last := false; -- first := true; -- while not last loop -- my_comb.comb(N, M, Vn, Vm, first, last); -- -- use Vm combination -- end loop; generic Max_Size : integer; -- user max size type Item is private ; -- user item type type Vector_Type is array(integer range <>) of Item; -- user vector type package Combinations is type Comb_Type is array(Integer range <>) of Integer; C : Comb_Type(0..Max_Size+1); Pos : Integer; Var : Integer; Mov : Integer; procedure Comb(N : Integer; M: Integer; Vn : in Vector_Type; Vm : in out Vector_Type; First : in out Boolean; Last : in out Boolean); end combinations;