MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: combinations of n objects 2 at a time


Albert Maydeu-Olivares wrote:
> 
> Hello,
> 
> In order to generate all combinations of n objects 2 at a time I load
> the `DiscreteMath` add-on.
> 
>  <<DiscreteMath`Combinatorica`
> 
> l[n_]:=rt[Ksubsets[Reverse[Table[i,{i,n}]],2]]
> 
> So that with n=objects I get
> 
> l[6]
> 
> {{2,1},{3,1},...,{6,4},{6,5}}
> 
> Any suggestions on how to do this without loading the add-on?
> 
Here is direct code:  

l[n_]:= Flatten[Table[{i,j},{i,2,n}, {j,i-1}],1]


Bill Knox

e-mail to:  bknox at snet.net


  • Prev by Date: cov matrix of sample means, variances and covariances
  • Next by Date: Nonconvex polygon rendering
  • Previous by thread: Re: combinations of n objects 2 at a time
  • Next by thread: Compile and NormalDistribution