Re: Q: extract all k-tuple from a list of n elements

*To*: mathgroup at smc.vnet.net*Subject*: [mg49730] Re: Q: extract all k-tuple from a list of n elements*From*: pnardon <pnardon at ulb.ac.be>*Date*: Thu, 29 Jul 2004 07:45:34 -0400 (EDT)*References*: <ce2fv9$8rm$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Klaus Duellmann wrote: > Question: How can I extract all k-tuple from a list of n elements > (without considering permutations of the k-tuple)? > > Example: For the special case k=3 one solution would be > > Flatten[Table[{i, j, k}, {i, 1, n - 2}, {j, i + 1, n - 1}, {k, j + 1, > n}], 2]; > > A generalization of this solution for all k >=1 would involve to create > 'automatically' a table of dimension k, but how can this be implemented? > > Any help is appreciated. > > Regards, > > Klaus > TuTu[el_, n_] := Map[Sort[Join[el, {#}]] &, Complement[Range[n], el]]; ZaZa[x_, n_] := Complement[Flatten[Map[Sort[TuTu[#, n]] &, x], 1], {}]; ZZZ[m_, n_] := Module[{tmp}, tmp = Complement[Flatten[Map[TuTu[{#}, n] &, Range[n]], 1], {}]; Nest[ZaZa[#, n] &, tmp, m - 2]] ZZZ will give the answer (be carefull m>1) m gives the dimensions that you want n gives the range needed In[395]:= ZZZ[8,10] Out[395]= {{1,2,3,4,5,6,7,8},{1,2,3,4,5,6,7,9},{ 1,2,3,4,5,6,7,10},{1,2,3,4,5,6,8,9},{1,2,3,4,5,6,8,10},{1,2,3,4,5, 6,9,10},{1,2,3,4,5,7,8,9},{1,2,3,4,5,7,8,10},{1,2,3,4,5,7,9,10},{1,2,3,4, 5,8,9,10},{1,2,3,4,6,7,8,9},{1,2,3,4,6,7,8,10},{1,2,3,4,6,7,9,10},{1,2,3, 4,6,8,9,10},{1,2,3,4,7,8,9,10},{1,2,3,5,6,7,8,9},{1,2,3,5,6,7,8,10},{1,2, 3,5,6,7,9,10},{1,2,3,5,6,8,9,10},{1,2,3,5,7,8,9,10},{1,2,3,6,7,8,9,10},{ 1,2,4,5,6,7,8,9},{1,2,4,5,6,7,8,10},{1,2,4,5,6,7,9,10},{1,2,4,5,6,8,9, 10},{1,2,4,5,7,8,9,10},{1,2,4,6,7,8,9,10},{1,2,5,6,7,8,9,10},{1,3,4,5,6, 7,8,9},{1,3,4,5,6,7,8,10},{1,3,4,5,6,7,9,10},{1,3,4,5,6,8,9,10},{1,3,4, 5,7,8,9,10},{1,3,4,6,7,8,9,10},{1,3,5,6,7,8,9,10},{1,4,5,6,7,8,9,10},{2, 3,4,5,6,7,8,9},{2,3,4,5,6,7,8,10},{2,3,4,5,6,7,9,10},{2,3,4,5, 6,8,9,10},{2,3,4,5,7,8,9,10},{2,3,4,6,7,8,9,10},{2,3,5,6,7,8,9,10},{2,4, 5,6,7,8,9,10},{3,4,5,6,7,8,9,10}} -- Pasquale Nardone UniversitÂ? Libre de Bruxelles Physique GÂ?nÂ?rale CP 231, Sciences-Physique-AgrÂ?gation Bld du Triomphe, 2 1050 Bruxelles, Belgium tel: +32.2.6505515 tel secr: +32.2.6505618 fax: +32.2.6505332 web: http://homepages.ulb.ac.be/~pnardon/ ou encore http://physinfo.ulb.ac.be/