Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permutations

Status
Not open for further replies.

randie

Programmer
Jan 20, 2000
3
US
Can anyone give me an easy algorithym to list all possible combinations of letters in a word?<br>
<br>
thanks in advance<br>
randie
 
look at &quot;INSTR&quot;<br>
---------------------------------<br>
For a = 1 To Len(Text1)<br>
' finds ALL positions of the letter &quot;A&quot;<br>
Letter = InStr(a, Text1, &quot;A&quot;)<br>
If Letter Then<br>
Debug.Print &quot;Letter A at Position &quot;; a<br>
a = Letter + 1<br>
End If<br>
Next<br>
<br>
------------------------<br>
IF Text1 contains &quot;ABCAFGHAFETYAGERA&quot;<br>
The results are<br>
Letter A at Position 1 <br>
Letter A at Position 3 <br>
Letter A at Position 6 <br>
Letter A at Position 10 <br>
Letter A at Position 15 <br>
<br>
When the sub routine is run<br>

 
Randie, depends on how WORD is defined: if your going against the Oxford Unabridged You have some Houres to put in .. HOWEVER, if The WORD is a PASSWORD with just 26 (alpha only) possible entries per position. ...........<br>
then 2 positions would be 26 times 26 ......<br>
4 positions would be 26 X 26 X 26 X 26 ......
 
If you want to know how many &quot;A&quot;'s are there?<br>
Add a counter like so<br>
Same code as above with 2 lines added<br>
<br>
Counter1=0 '&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; ------- add this line<br>
For a = 1 To Len(Text1)<br>
' finds ALL positions of the letter &quot;A&quot;<br>
Letter = InStr(a, Text1, &quot;A&quot;)<br>
If Letter Then<br>
Debug.Print &quot;Letter A at Position &quot;; a<br>
a = Letter + 1<br>
Counter1=Counter1+1 '&lt;&lt;&lt;&lt;----added this line too<br>
End If<br>
Next<br>
Debug.print Counter1<br>
<br>
Counter1 will be 6 for my example above
 
Previous reply is not clear enough!! (co-worker.).....<br>
for each single letter when made into a two letter combo<br>
A would become A + (A thru Z) thru the alphabet until...<br>
Z would become Z + (A thru Z) .......<br>
Then Each Double, AA becomes AA + (A thru Z) and ... <br>
each ZZ becomes ZZ + (A thru Z) until and ect. ... <br>
Each AAAA Becomes AAAA + (A thru Z) and ect. .. <br>
each ZZZZ becomes ZZZZ + (A thru Z) ...<br>
(co-worker now ok)
 
Thanks ya'll but I don't think I made my problem clear enough. I will try again.<br>
<br>
I don't need to know how many of a letter there are or how many combinations there are. If I know how many letters and what the letters are, I want to be able to give them all of the possible combinations of letters as follows: Your word: AND, possible combinations 6, AND, ADN, NAD, NDA, DAN, DNA<br>
<br>
I can accomplish this by using If... Then as follows:<br>
<br>
If x = 1 Then<br>
txtAnagram2.Text = UCase(a)<br>
txtNumber.Text = 1<br>
End If<br>
If x = 2 Then<br>
txtAnagram2.Text = UCase(a + b) & vbCrLf & UCase(b + a)<br>
txtNumber.Text = 2<br>
End If<br>
<br>
Etc....<br>
<br>
But I am sure there is a better way???<br>
<br>
Thanks again,<br>
randie<br>
<br>

 
Randie<br>
<br>
The problem you are goind to have here is the the number of permutations (which is calculated using n!) rises VERY rapidly, e.g. a three-letter word has 6 permutations, a six-letter word has 720 and a nine-letter word has 362,880. Calculating them is simple but how do you want to present them? A TextBox can only hold 32K (35K would be needed to hold the output for the seven-letter permutation. The reason I ask is that the calculation method will depend on this as well as other knowledge such as the number of letters to be used. If you can give me some more details I can submit a solution.<br>
<br>
-Ian
 
Ian:<br>
<br>
Thank you for your help in this matter. I did not realise that a textbox could only hold 32K. I was thinking of a textbox and limiting their word to 5 or 6 characters. <br>
<br>
Thanks,<br>
randie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top