|
-
May 26th, 2000, 01:18 AM
#1
Thread Starter
Hyperactive Member
Does anyone have an idea of how to take three letters a,b,c and then find all the possible combinations? Thanks
Matt 
-
May 26th, 2000, 01:38 AM
#2
transcendental analytic
What are you doing? programming something? tell more
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 26th, 2000, 05:22 AM
#3
An interesting problem
I'm sure there is a more elegant way, but this works.
Code:
Dim intIndex1 As Integer
Dim intIndex2 As Integer
Dim intIndex3 As Integer
Const LETTERS = "abc"
For intIndex1 = 1 To 3
For intIndex2 = 1 To 3
For intIndex3 = 1 To 3
If intIndex1 = intIndex2 Or _
intIndex1 = intIndex3 Or _
intIndex2 = intIndex1 Or _
intIndex2 = intIndex3 Or _
intIndex3 = intIndex1 Or _
intIndex3 = intIndex2 Then
' Don't print because it will have duplicate letters
Else
Debug.Print Mid$(LETTERS, intIndex1, 1) & _
Mid$(LETTERS, intIndex2, 1) & _
Mid$(LETTERS, intIndex3, 1)
End If
Next
Next
Next
-
May 26th, 2000, 05:54 AM
#4
transcendental analytic
I like that one Martin, could you make one that handles n letters?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 26th, 2000, 06:02 AM
#5
I just studied his code a bit and I beloieve thaat you just add on to intIndex#, and ad the necessary commads to make it function with 4.
-
May 26th, 2000, 06:26 AM
#6
transcendental analytic
Meg, that was not what i meant. I meant that you could put your letters in a dynamic array and then get a dynamic array out containing all combinations.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 26th, 2000, 11:26 PM
#7
Thread Starter
Hyperactive Member
looks good
Looks good martin, if anyone was wondering I am doing this for a math probablility problem where I need to find all possible combinations.
Matt 
-
May 26th, 2000, 11:56 PM
#8
Frenzied Member
it's easier just to work it out
what do you mean by the number of combinations of the letters a,b,c
do you mean the possible orders of the 3 letters
abc
acb
bac
bca
cab
cba
or if you allow repeats ie aab or aaa then it's 3^3 = 27
just stick your problem up.
-
May 27th, 2000, 12:31 AM
#9
But whewn you get into bigger numbers, it might be a difficult to do all of them mechanically.
-
May 27th, 2000, 12:53 AM
#10
this leads to some serious numbers. a whole alphabet's worth will return (6.15611958 x 10E36).
My scientific calculator packs up at 56^56 (7.9 x 10E97) !
-
May 27th, 2000, 01:26 AM
#11
This type of code can be used to crack passwords. It keeps trying every single letter combonation until it gets it right.
-
May 27th, 2000, 02:33 AM
#12
Thread Starter
Hyperactive Member
you could
yes you could figure it mechically but that will get very confusing quickly as I found out. Im working on a soultion that I think will work. I will post it when I finish
Matt 
-
May 27th, 2000, 02:47 AM
#13
Frenzied Member
post up the question, i'll put the answer, but you'll have to give it in a bit more detail than you did.
-
May 27th, 2000, 09:22 PM
#14
This works for any combination of letters
Thos works for any number of letters and any combination including strings like "abAcd".
[Deleted: See my updated post further down.]
[Edited by MartinLiss on 05-28-2000 at 08:03 AM]
-
May 27th, 2000, 09:40 PM
#15
transcendental analytic
Great work Martin! Thanks
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 27th, 2000, 09:57 PM
#16
You're welcome, but I needed to modify it because ints just don't do it when you can have millions of combinations.
Code:
Dim dblFactorial As Double
Dim intLen As Integer
Dim intColumn As Integer
Dim intLetter As Integer
Dim dblRepeats As Double
Dim dblEntry As Double
Dim dblRepFactor As Double
Dim strCombos() As String
Dim bIsUsed() As Boolean
Const LETTERS = "abcde"
' Determine the number of letters
intLen = Len(LETTERS)
' Calculate the number of combinations of letters
' For 4 letters that would be 4 * 3 * 2 * 1 = 24
dblFactorial = intLen
Do Until intLen = 1
intLen = intLen - 1
dblFactorial = dblFactorial * intLen
Loop
' ...and dim the array to hold just that many
ReDim strCombos(dblFactorial - 1)
' Restore the number of letters since we decremented it in the factorial calc
intLen = Len(LETTERS)
' Dimension the table that will record which letters have been used in
' which locations, so that duplicates can be avoided
ReDim bIsUsed(dblFactorial - 1, intLen - 1)
' Set an initial value for the letter repeat factor
dblRepFactor = dblFactorial / intLen
' Build the "columns" vertically
For intColumn = 0 To intLen - 1
intLetter = 1 ' When the column changes, start the letters over again
For dblEntry = 0 To dblFactorial - 1
Do While bIsUsed(dblEntry, intLetter - 1)
' The pending letter is already in the combo so try the next one...
intLetter = intLetter + 1
If intLetter > intLen Then
' ...but don't go "off the end" of the letters
intLetter = 1
End If
Loop
' OK, we've got a valid entry so record it
strCombos(dblEntry) = strCombos(dblEntry) & Mid$(LETTERS, intLetter, 1)
bIsUsed(dblEntry, intLetter - 1) = True
' Keep track of how many times a given letter has been repeated...
dblRepeats = dblRepeats + 1
If dblRepeats = dblRepFactor Then
' ...and when it's at its max, start over again
dblRepeats = 0
intLetter = intLetter + 1
If intLetter > intLen Then
intLetter = 1
End If
End If
Next
' Recalculate the repeat factor for the next "column"
If dblRepFactor > 1 Then
dblRepFactor = dblRepFactor / (intLen - (intColumn + 1))
End If
Next
For dblEntry = 0 To UBound(strCombos)
Debug.Print strCombos(intLetter)
Next
-
May 28th, 2000, 08:45 AM
#17
Frenzied Member
VB Permution Generator
A similar question was posted a few months ago. It got me interested in writing a VB version of a Mainframe program I wrote many years ago.
My VB application provides a text box into which a string is entered. Command Buttons can be used to generate permutations of the bytes in the string (either all at once or one at a time). The permuations are put into a List Box.
If anyone is interested, I will send the VB Files used by my application (I have not deployed the application). I am running VB 6 under windows 98.
The algorithm appeared in Scientific American about 20 years ago, and is considered the best possible method. I do not have a good description of the algorithm, and do not want to create one (it is easier to show examples than to describe how to do it). The VB application makes the approach obvious.
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.
-
May 28th, 2000, 08:58 AM
#18
Fanatic Member
Yes please,
I've been coding up the DES spec and my coding of the permutations if slowing everything. It works but its too slow for large files, I'd like to see some better permutation algorithms to get some better ideas.
[email protected]
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
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
|