 |

10-06-2006, 08:31 PM
|
|
Junior Contributor
|
|
Join Date: Sep 2005
Posts: 228
|
|
Dis-Assemble
|
I want to take a base word, and dis-assemble it into all the possiblities.
For example, i wanna take the word mike, and make these combos:
mike
mik
mke
mie
me
mi
mk
ik
ie
ke
Its basically removing a letter, and making combos for the letters there.. Does that make sense?
|
|

10-06-2006, 09:55 PM
|
 |
Multi-Technologist
Super Moderator * Expert *
|
|
Join Date: May 2004
Location: Michigan
Posts: 3,740
|
|
This is not exactly what you want, but it should give you some ideas. Just add two textboxes to a form, making the second one multiline:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim I As Long
Dim L As Long
Dim N As String
Dim OS As String
Dim NA() As Boolean
Dim NB() As String
If KeyAscii = 13 Then
N = Text1.Text
L = Len(N)
If L Then
ReDim NA(L)
ReDim NB(L)
For I = 1 To L
NB(I) = Mid(N, I, 1)
Next
Do
OS = ""
For I = 1 To L
If NA(I) = False Then OS = OS & NB(I)
Next
For I = L To 1 Step -1
NA(I) = NA(I) + 1
If NA(I) = True Then Exit For
Next
If Len(OS) Then Text2.SelText = OS & vbCrLf
Loop While Len(OS)
End If
End If
End Sub
|
|

10-06-2006, 09:57 PM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
|
|
|
Since you should do your own homework, hopefully the above is not too close to what you want.
Of course, the instructor might want you to explain it, so if you can do that, maybe you'll have learned something to make it worth it.
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
|

10-06-2006, 10:09 PM
|
|
Junior Contributor
|
|
Join Date: Sep 2005
Posts: 228
|
|
|
my homework? its a personal project im working on. im working on a program that uses a dictionary reference, and takes a bunch of letters, and dis-assembles them, then checks each combination of the letters for a word match.
but thanks passel for thinking its homework!
|
|

10-07-2006, 12:21 AM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
|
|
|
Well, based on your example, it doesn't look like it does all combinations.
You want it to give you ike, but not kie, or eik, etc., so you want the characters in their original order, but they don't have to be contiguous, so you're not looking for subwords in existing words.
Those two cases, matching subwords, or finding all combinations or permutations I could see some applications for.
Choosing all groups of letters in the same order but not necessarily contiguous is an ideal recursion programming problem, so looks just like an exercise you would get in a class on recursive programming.
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Last edited by passel; 10-07-2006 at 01:27 AM.
|

10-07-2006, 02:07 PM
|
|
Junior Contributor
|
|
Join Date: Sep 2005
Posts: 228
|
|
|
I have a great permutation example, does all possible combos, but it generates way too many. I dont want my program to take an hour searching 20,000 possible comboinations for words in the dictionary.
|
|

10-08-2006, 01:18 AM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
|
|
|
Well, as I said, it looks like a good job for a recursive routine.
I haven't done a lot of recursive routines, so don't know if this is the best approach, but I would write a routine that accepts a string and a number. The string will represent the string at the current stage level of recursion, and the number will represent what character index the caller is working on.
The routine will just loop from the next character (the character passed in + 1) through the number of characters. It will append the character to the original string passed in and print it (or save it, or whatever you want to do).
It would then call itself passing the string in its current state (with the appended character) and the character index (the value of the loop counter)
The recursion allows all the combinations to be created with a minimum amount of code (about six lines of code).
If you call the recursive routine passing a null string and 0, then all combinations meeting your criteria, will be created, including single letter words.
Assuming you don't want single letter words, you could either add a simple test in the recursion routine to not print single letter words, or you could call the recursive routine in a loop, passing each of the single characters of the string and the index of that character. Since you don't print the single character in your loop, the recursive routine will be appending characters to that orignal one character string you passed in, so will print 2,3,4 etc character length strings.
That routine would also print the full string, so you would add a check in the recursive routine to not print the word if its length was the same as the original word, assuming you don't want the original word as part of your list.
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|