~Bean~ Level: VB Guru

 Registered: 07-04-2003 Posts: 488
|
Re: All possible combination of number
I believe you're looking for code to determine the permutations of a string...
i.e.,
Permutations of string of length n = n!
in this case..."159"...
159 => 3! = 1*2*3 = 6 Which implies there are 6 permutations of the string "159" (or any 3 character string for that matter) =>{159},{195},{951},{915},{591},{519}
(for longer lengths of strings, programs typically use disk access to avoid memory overflow [i.e., n > 10]...and keep in mind the limit of number of items that a list box can hold, 32K I think)
There are almost as many ways (algorithms) to arrive at all the possible sets as there are permutations of 25!...lol...ahem...needless to say the technique you use may depend on the length of your string, whether this length varies, and whether speed is a real factor (*see FYI below). Code snippets can be lengthy for this type of operation - I have several which I found lying around which I can e-mail to you if you like, otherwise search your favorite code website for "permutation" and see what you find...
~Beans~ FY Du Jour - n! Beyond our Capabilities
Regarding permutations...
2! = 2
5! = 120
10! = 3,628,800
15! = 1,307,674,368,000
phew...
20! = 2,432,902,008,176,640,000 WOW!
Could you actually list the sets of 20! ?
Given current level of tech (CPU speed)...say, 1 billion permutations per second that 20! would take
2,432,902,008 seconds, or
40,548,367 minutes, or
675,806 hours, or
28,159 days, or
77 years!

WOWZERS!
[Edited by ~Bean~ on 02-06-2003 at 06:25 PM GMT]
____________________________
Eggheads unite! You have nothing to lose but your yolks.
|