Generating all possible combination of elements in a list

"Martin v. Löwis" martin at v.loewis.de
Tue Jul 25 13:44:10 EDT 2006


Mir Nazim wrote:
> condition are there cannot be more than 3 consecutive 2's or 1's
> 
>> If the task is to produce all distinct permutations of 6 occurrences
>> of 1 and 6 occurrences of 2, I suggest the program below. It needs
>> produces much fewer than 12! results (namely, 924).
>>
> 
> Yes that number I had already worked out and it is 792 for second list.
> Now I have generated all distinct permutations and after eliminating
> the permutations based on above condition I am left with 1060
> permutations.

Again, I don't understand. You have 924 things, eliminate some of them,
and end up with 1060 things? Eliminating elements should decrease
the number, not increase it.

> Now I ahave a lits with 1060 lists in it. Now comes the hard part.
> How many possible distinct ways are there to arrange 1060 elements
> taken 96 at a time
> 
> 1060! / (1060 - 96)!

Well, this gives you

3179049214270213494856036082395246272767603703117029227219760559555570970143122666905356954926552940841376332310832740817342891028120773779767941521978678527871167070887214646849981846725146620998653633794832176123350796907123110479415043912870243292225353946234880000000000000000000000000

lists. Assuming you have a 4GHz machine, and assuming you can
process one element per processor cycle (which you can't in
any programming language), you would still need

25201747322664680800165176959627459671229735089398062747493028281611261495934191613595232075457833435132676404036916070660062238617142105686897050370835541348547430483314423570284610022871849798632147655019915145574508473705630949386534784951089574551507435520000000000000

years to process them all. Even if you had 10000000000
computers (i.e. one per human being on the planet), you
still need ... you get the idea.

> Now out of these i need to test only those lists whose sum of
> elements(18 or 19) follows a particular pattern.

To succeed, you must take this condition into account.
What is the particular pattern?

Regards,
Martin



More information about the Python-list mailing list