|
-
Sep 7th, 2000, 08:33 PM
#1
Thread Starter
Addicted Member
I'm pretty sure this is called permutation. WHat I need to do is take a variable number of letters/numbers an compute all the possible combinations. Example:
Given string: abc
Results:
abc
acb
bca
bac
cab
cba
And I have no clue as to how to do this. I need to be able to do this with any number of letters up to 10 at least. Code would be great. But if you could explain the process that would be good too.
Thanks in advance.
Cbomb
Techie 
-
Sep 7th, 2000, 08:42 PM
#2
Frenzied Member
I dont have the time to write it but this is how it works... you break up every letter in the word into a seperate string...then you randmoize putting the string togehter in diffrent ways and then putting all of that into a list box, or what ever you need... If I had lots of time on my hands I would give you the code. and If i did then it will be like 100 pages long becuase II dont know how to make it short
NXSupport - Your one-stop source for computer help
-
Sep 7th, 2000, 08:42 PM
#3
Frenzied Member
This is like the nPr thing you see on your scientific calculator. I'm not sure what the formula is off the top of my head, I'll look it up a sec (assuming someone doesn't answer it already).
Harry.
"From one thing, know ten thousand things."
-
Sep 7th, 2000, 08:46 PM
#4
Frenzied Member
P(n,k) = n·(n-1) ···(n-k+1) = n!/k!
wheere P(n,k) is the number of permutations (a function of n & k), n is the number of different possible values (3 if you're using the set {a, b, c} for example), and k is the length of your string.
Harry.
"From one thing, know ten thousand things."
-
Sep 7th, 2000, 08:54 PM
#5
Frenzied Member
Harry.
"From one thing, know ten thousand things."
-
Sep 7th, 2000, 09:00 PM
#6
Try this:
Code:
'Code from Megatron
For I = 0 To 25
fChar = 97 + I
For x = 0 To 25
sChar = 97 + x
For y = 0 To 25
List1.AddItem Chr(fChar) & Chr(sChar) & Chr(97 + y)
Next y
Next x
Next I
-
Sep 7th, 2000, 09:02 PM
#7
Frenzied Member
D'oh! I'm not just racking up my post count here, honest Looking at that formula something's wrong with it, here's the right one:
nPr = n!/(n-r)!
If n = r then nPr = n!.
Sorry, wrong letters so I edited it.
[Edited by HarryW on 09-07-2000 at 10:10 PM]
Harry.
"From one thing, know ten thousand things."
-
Sep 7th, 2000, 09:56 PM
#8
Thread Starter
Addicted Member
-
Sep 8th, 2000, 01:31 PM
#9
Frenzied Member
Do exchanges of first letter.
The number of permutations goes up fast: 8 Letters (40,320), 10 (3,628,800), 12 (479,001,600).
The best way to generate them can be done recursively. The general idea is to move the first letter in the string right and left (ABCDEFG, BACDEFG. BCADEFG, BCDAEFG). When first letter gets to one end or the other, advance second letter once before reversing direction of first letter (BCDEFGA, CBDEFGA, CBDEFAG, CBDEAFG). Similarly, when second letter gets to an extreme position, advance third letter.
The advantage of this method, is that the first letter is moved a huge number of times. It is kept in a temporary location and inserted into the string as required. Thus, most of the exchanges are "half-exchanges" instead of "full exchanges."
I created a simple VB application which does the above to illustrate the algorithm for a few bright teenage friends. I can Zip the VB files I used and send them to you if you want.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Sep 8th, 2000, 07:35 PM
#10
Thread Starter
Addicted Member
Oh ok I get it now. If you could send that it would be great! [email protected]
Thanks!
Cbomb
Techie 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|