Finding all possible combinations of elements in variable length lists

From: Jon Erickson (jon_e_erickson_at_hotmail.com)
Date: 11/30/04


Date: 29 Nov 2004 15:07:52 -0800

I have a list that contains many lists with variable number of
elements:

ListOfLists[0] = { 1, 3, 4 }
ListOfLists[1] = { 6, 2, 8 }
ListOfLists[2] = { 9, 7 }
...
ListOfLists[n]

I need an algorigthm that will produce all the possible combinations
that can be generated by taking one element from each list:

{1, 6, 9 }
{1, 6, 7 }
{1, 2, 9 }
{1, 2, 7 }
{1, 8, 9 }
{1, 8, 7 }
...

For some reason I cannot think of a good way to do this... can hit me
over this head with a clue stick?

Thanks,

Jon Erickson



Relevant Pages

  • Re: Finding all possible combinations of elements in variable length lists
    ... Jon Erickson wrote: ... > I have a list that contains many lists with variable number of ... > I need an algorigthm that will produce all the possible combinations ... Well, it's not that easy to come up with such a terse solution, ...
    (comp.programming)
  • Re: Finding all possible combinations of elements in variable length lists
    ... Jon Erickson wrote: ... > I need an algorigthm that will produce all the possible combinations ... duplicated across the lists AND you really mean combinations, ... then generate ordered lists, which would maintain the order of elements ...
    (comp.programming)
  • Re: Finding all possible combinations of elements in variable length lists
    ... > I need an algorigthm that will produce all the possible combinations ... by one combination of elements of the remaining lists. ... (defun combinations (lists) ... Matthieu Villeneuve ...
    (comp.programming)
  • Re: GUMBY GRUB
    ... > Ive been on redhat lists for years and years and years, ... > I dont accept the feedback on this list either, ... > without a clue have no access to my desktop, mail servers, or RH's mail ...
    (Fedora)
  • Re: GUMBY GRUB
    ... Ive been on redhat lists for years and years and years, ... I dont accept the feedback on this list either, ... without a clue have no access to my desktop, mail servers, or RH's mail ...
    (Fedora)