Permutations

TheMightyAtom

Member
Joined
Jul 19, 2008
Messages
5
Programming Experience
1-3
If I have a collection of integers how can I find every combination permuatation of these integers?
e.g.
1,2,3,4,1and2,1and3,1and4,2and3,2and4,1and2and3,1and2and4,etc

Any help would be very gratefully received!
 
Ah, nearly but not quite.

These are factorials e.g. 1234,1324,1432,1423

What I am so struggling to recreate is all combinations but not repeating any of the numbers, in any of the combinations
1,2,3,4,12,13,14,21,23,24,.....1234
Any ideas?
 
I agree it was designed to find variations of a fixed length string, but it can be accommodated for your need also. All you need to do is add a "space" as one of the available chars in charset. So you get " 1", " 2" etc. which you can Trim or CInt. I haven't compared the speed of these methods yet, so I can't tell if my counting method was just a fun experiment or what. My method will in this case put for example "1" in various places like " 1", " 1 ", "1 " which would be the same value in the end, so one would have to cater for this also. Another option is running the algorithm for 1 to number of chars in charset, so you get one loop for string length 1, one for length 2 etc.
 
Back
Top