*
* @GenCombos n k
*
* Systematically generates all combinations of k integers from the set
* {1,...,n}. All this procedure does is to generate them as the vector
* of integers "pick". If you need to do something more than this, insert
* the necessary code at the "disp pick" instruction.
*
*   07/05 Written by Tom Doan, Estima
*
proc GenCombos n k
type integer n k
*
local vect[integer] pick
local integer j i
*
dim pick(k)
*
ewise pick(i)=i
loop {
   disp pick
   do j=k,1,-1
      if (pick(j)+(k-j)<n)
         break
   end do j
   if j==1.and.pick(1)==(n-k+1)
      return
   compute pick(j)=pick(j)+1
   do i=j+1,k
      compute pick(i)=pick(i-1)+1
   end do i
}
end

