MathGroup Archive 2004

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

Search the Archive

RE: Creating combinations from a group of sets

  • To: mathgroup at smc.vnet.net
  • Subject: [mg48705] RE: [mg48679] Creating combinations from a group of sets
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 11 Jun 2004 03:52:28 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Jeanette,

Use Outer.

Flatten[Outer[List, {1, 2, 3}, {4, 5}, {6}, {7, 8}], 3]
{{1, 4, 6, 7}, {1, 4, 6, 8}, {1, 5, 6, 7}, {1, 5, 6, 8}, {2, 4, 6, 7}, {2,
4,
    6, 8}, {2, 5, 6, 7}, {2, 5, 6, 8}, {3, 4, 6, 7}, {3, 4, 6, 8}, {3, 5, 6,
    7}, {3, 5, 6, 8}}

Inner is also a neat command when you want to combine elements of two equal
length objects with the same head. For example..

eqn1 = a == b;
eqn2 = b == c;
Inner[Divide, eqn1, eqn2, Equal]
a/b == b/c

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/


-----Original Message-----
From: Jeanette L Domber [mailto:Jeanette.L.Domber at aero.org]
To: mathgroup at smc.vnet.net
Subject: [mg48705] [mg48679] Creating combinations from a group of sets



I have a group of sets:

{1,2,3}
{4,5}
{6}
{7,8}

I wish to create all unique combinations of the sets that contain exactly
one element from each set:

{1,4,6,7}
{1,5,6,7}
{1,4,6,8}
{1,5,6,8}
{2,4,6,7}
{2,5,6,7}
etc.

In all, there should be 12 combinations.

If I use KSubsets giving it a list {1,2,3,4,5,6,7,8} to create combinations
containing 4 elements, I get a list of 70 combinations, 58 of which are
extraneous to my application.

Does anyone know how to manipulate the functions in
DiscreteMath`Combinatorica` to accomplish this efficiently?

Thanks,
    Jeanette




  • Prev by Date: Re: faster sublist checking
  • Next by Date: Re: faster sublist checking
  • Previous by thread: Re: Creating combinations from a group of sets
  • Next by thread: Re: Creating combinations from a group of sets