Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1992
*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 1992

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

Search the Archive

combination function

  • To: mathgroup at yoda.physics.unc.edu, serhody at rodan.acs.syr.edu
  • Subject: combination function
  • From: gaylord at ux1.cso.uiuc.edu
  • Date: Fri, 28 Feb 1992 06:54:10 -0600

yet another way:

subsets[x_List] := Sort[Flatten/@Distribute[{{},{#}}&/@x, List]]

combo[x_List, r_Integer] := Cases[subsets[x], Table[_, {r}]]

combo[{a, b, c, d}, 3]
{{a, b, c}, {a, b, d}, {a, c, d}, {b, c, d}}

combo[{a, b, c, d}, 2]
{{a, b}, {a, c}, {a, d}, {b, c}, {b, d}, {c, d}}

================================================

using the subset function taken from somewhere (possibly an issue of
Mathematica J., perhaps a one-liner therein?)

subsets[x_List] := 
							Sort[Flatten/@Distribute[{{},{#}}&/@x, List]]

combination[x_List, r_Integer] := 
  Select[subsets[x], Length[#] == r&]


combination[{a, b, c, d}, 3]
{{a, b, c}, {a, b, d}, {a, c, d}, {b, c, d}}


combination[{a, b, c, d}, 2]
{{a, b}, {a, c}, {a, d}, {b, c}, {b, d}, {c, d}}










  • Prev by Date: Re: animation
  • Previous by thread: international trade model