Re: Creating combinations from a group of sets
- To: mathgroup at smc.vnet.net
- Subject: [mg48707] Re: [mg48679] Creating combinations from a group of sets
- From: János <janos.lobb at yale.edu>
- Date: Fri, 11 Jun 2004 03:52:30 -0400 (EDT)
- References: <200406100643.CAA29466@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Here is a procedural approach newbie style: x1 = {1, 2, 3}; x2 = {4, 5}; x3 = {6}; x4 = {7, 8}; x = {x1, x2, x3, x4} a[n_] := Map[Length, x[[n]] ] For[i = 1, i ² a[1], i++, For[j = 1, j ² a[2], j++, For[k = 1, k ² a[3], k++, For[l = 1, l ² a[4], l++, Print[{x1[[i]], x2[[j]], x3[[k]], x4[[l]]}]]]]] I am sure all these For-s can be written with Map, but it does not hit me how. I also do not know what to do when you have 1000 lists, but it shows that it can be done. Wizards in other posts will show you the magic. J?nos On Jun 10, 2004, at 2:43 AM, Jeanette L Domber wrote: > > 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 > > ------------------------------------------------- clear perl code is better than unclear awk code; but NOTHING comes close to unclear perl code http://www.faqs.org/faqs/computer-lang/awk/faq/
- References:
- Creating combinations from a group of sets
- From: Jeanette L Domber <Jeanette.L.Domber@aero.org>
- Creating combinations from a group of sets