Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: combinations of n objects 2 at a time

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15219] Re: combinations of n objects 2 at a time
  • From: Bill Knox <bknox at snet.net>
  • Date: Tue, 22 Dec 1998 04:01:48 -0500
  • References: <75cvud$3u8@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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