Results 1 to 18 of 18

Thread: combination of letters

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Question

    Does anyone have an idea of how to take three letters a,b,c and then find all the possible combinations? Thanks
    Matt

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  5. #5
    Guest
    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.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  7. #7

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Thumbs up 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

  8. #8
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    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.

  9. #9
    Guest
    But whewn you get into bigger numbers, it might be a difficult to do all of them mechanically.

  10. #10
    Guest
    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) !

  11. #11
    Guest
    This type of code can be used to crack passwords. It keeps trying every single letter combonation until it gets it right.

  12. #12

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Arrow 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

  13. #13
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    post up the question, i'll put the answer, but you'll have to give it in a bit more detail than you did.

  14. #14
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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]

  15. #15
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  16. #16
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    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

  17. #17
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    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.

  18. #18
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    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
  •  



Click Here to Expand Forum to Full Width