Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*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 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: [mg48703] Re: [mg48679] Creating combinations from a group of sets
  • From: Adriano Pascoletti <pascolet at dimi.uniud.it>
  • Date: Fri, 11 Jun 2004 03:52:26 -0400 (EDT)
  • References: <200406100643.CAA29466@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Il giorno 10/giu/04, alle 08:43, Jeanette L Domber ha scritto:

>
> 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.

Hi,
use Outer[List, l1, l2,...,ln] followed by Flatten[...,n-1]

In[41]:=
Outer[List,{1,2,3},{4,5},{6},{7,8}]

Out[41]=
{{{{{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}}}}}

In[43]:=
Flatten[%,3]

Out[43]=
{{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}}

A. Pascoletti

------------------------------------------------------------------------ 
--------

Adriano Pascoletti
Dipartimento di Matematica e Informatica
Universita' di Udine
Via delle scienze 206
I-33100 Udine
Italy



  • Prev by Date: Merging lists if an element in each partially matches?
  • Next by Date: Re: Energy content of a mathematical result.
  • Previous by thread: Creating combinations from a group of sets
  • Next by thread: Re: Creating combinations from a group of sets