Subj : Re: Algorithm to generate permutation for a non sequential single array To : comp.programming From : cri Date : Fri Jul 01 2005 06:20 pm On 1 Jul 2005 09:07:12 -0700, "mmarin1m@hotmail.com" wrote: >Hi all, > >I'm looking for an algorithm that would generate all permutations for a >given non sequential list. As an example: > >Given the list 125, 126, 5, 88 and 33, all permutations must be >generated in that sequence. > >The perfect algorithm would yields the following matrix: > >125, 126, 5, 88, 33 >125, 126, 5, 88 >126, 5, 88, 33 >125, 126, 5 >125, 126, 88 >125, 126, 33 >125, 5, 88 >125, 5, 33 >125, 88, 33 >126, 5, 88 >126, 5, 33 >126, 88, 33 >5, 88, 33 >125, 126 >125, 5 >125, 88 >125, 33 >126, 5 >126, 88 >126, 33 >5, 88 >5, 33 >88, 33 >125 >126 >5 >88 >33 > >Sorry about the length of this post. > >The fact that the numbers are non sequential is irrelevant. What >matters is that 126 should never appears before 125, etc, etc. > >Thank you in advance, What you are asking for appears to be to list all of the sublists of your original list while retaining the original order. There will be 2**n of these (counting the empty list). Map the problem into bit strings of length n, using 1's to mark elements present. For n=3 S = {a,b,c} 111 -> a,b,c 110 -> a,b 101 -> a,c 011 -> b,c 100 -> a 010 -> b 001 -> c 000 -> Is this what you want? Richard Harter, cri@tiac.net http://home.tiac.net/~cri, http://www.varinoma.com Save the Earth now!! It's the only planet with chocolate. .