Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Generate All 17,576 combinations for 3 alpha places  (Read 11117 times)

0 Members and 1 Guest are viewing this topic.

DaveLembke

    Topic Starter


    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Generate All 17,576 combinations for 3 alpha places
« on: June 03, 2009, 10:06:24 PM »
Trying to find an easy way to generate all 17,576 combinations of __A thru ZZZ. Such as __A, __B, __C ......... _AA, _AB, _AC ...... AAA, AAB, AAC all the way to ZZZ. *With _ shown to indicate spaces for single and double combinations A-Z and AA to ZZ, and then all combinations of AAA thru ZZZ. The actual character '_' is not required and the list can be A, B, C ..... AA, AB, AC ..... AAA, AAB, AAC ....all the way to ZZZ.

My code will be either C++ or Perl (which ever makes more sense) which will read in this list of 17,576 combinations into an array list which will access all combinations 1 thru 17576 incremental for a process that runs and will take about 12 hours to complete all 17,576 repetitious routines to process data related to all cominations.

17,576 combinations is insane to have to manually code into a list for an array so I am here checking to see if there is an easy way to create this list or address all combinations in some other manner.

Even if there was a list already available that can be saved as a list.dat ( raw ascii text file ) that would work as for I can open this file and read in the contents into an array for incremental processing for all combinations.

Hoping there is an easy way to build this list -or-come up with this list of all cominations.  :-\

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: Generate All 17,576 combinations for 3 alpha places
« Reply #1 on: June 03, 2009, 10:25:26 PM »
I'm not so good with C++ or perl, but VB is my forte.

Code: [Select]
Public Function GetPermute() As String
Dim Chars As String
Chars = "_ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Dim currpermute As String
Dim outstr As String

Dim Char1 As Byte, char2 As Byte, char3 As Byte


For Char1 = 1 To Len(Chars) - 1
    For char2 = 1 To Len(Chars) - 1
        For char3 = 1 To Len(Chars) - 1
            outstr = outstr & Mid$(Chars, Char1, 1) & Mid$(Chars, char2, 1) & Mid$(Chars, char3, 1) & vbCrLf
           
   
        Next
    Next
   
Next
 'uncomment following line of you don't want underscores.
'outstr = replace$(outstr,"_","")
GetPermute = outstr

End Function


ahh yes, and if you want it to be in an array, split at the crlf's:

Code: [Select]
Dim strreturn as String
Dim valArray() as String
Strreturn = Getpermute()
valarray = Split(Strreturn,vbcrlf)
I was trying to dereference Null Pointers before it was cool.

gh0std0g74



    Apprentice

    Thanked: 37
    Re: Generate All 17,576 combinations for 3 alpha places
    « Reply #2 on: June 03, 2009, 10:41:00 PM »
    if you have Python....
    Code: [Select]
    import string
    alpha = string.uppercase
    x=(a+b+c for a in alpha for b in alpha for c in alpha)
    y=(a+b for a in alpha for b in alpha)
    z=(a for a in alpha )
    for i in [x,y,z]:
        for k in i:
            print k

    With Perl
    Code: [Select]
    for $x ( "AA" .. "ZZ"){
     print $x . "\n";
    }
    do the same with the rest.

    DaveLembke

      Topic Starter


      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Generate All 17,576 combinations for 3 alpha places
    « Reply #3 on: June 04, 2009, 10:38:49 AM »
    Hey Cool... Thanks both of you for your posts. I have many to pick from now and all will do what I need.

     Last night scribbling it on paper I was thinking that I was going to have to have a counter 1 to 26  to count to 26 and when 26 is reached increment the next alpha from 0 to 1, and when that variable incremented to 26 increment the next alpha variable place. Then of the numbers 0 - 26 where 0 = space, and 1 = A and 26 = Z, IF statements would be used to convert the numbers to the correct letters so 3,14,26 would be C,N,Z concatonated as CNZ into a list.

    The code you both provided shows that there was a far easier way to do this than my incremental x 26 shift register that would have been a huge beast to achieve the same results with nested for loops for each alpha place around a while loop that tested for Z,Z,Z or 26,26,26 to be met and exit the count process.

    MANY THANKS in saving me hours of troubles and pointing the best ways out!

    DaveLembke

      Topic Starter


      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Generate All 17,576 combinations for 3 alpha places
    « Reply #4 on: June 04, 2009, 11:16:14 AM »
    Playing with the Perl FOR statement that you provided it actually works in a single routine without need for others by A to ZZZ .... I am amazed at how simple this is with Perl...what an eye opener to simplicity. ha ha :o

    Going to save all your work to a PDF in case I find myself having to do this in the other languages. Suppose I should learn VB and Python as my next languages. The more you know the better off you are.

    Never knew that a FOR statement could increment Alpha like this, thought just Numeric and then a conversion would have to happen to switch the numerics to alpha A-Z or in this case A to ZZZ. Wonder if this is just a feature of Perl or if other languages also have been able to Alpha increment like this all along. Perl has many extra features to avoid reinventing the wheel and maybe this is one of them.

    Code: [Select]
    for $x ( "A" .. "ZZZ"){
     print $x . "\n";
    }

    gh0std0g74



      Apprentice

      Thanked: 37
      Re: Generate All 17,576 combinations for 3 alpha places
      « Reply #5 on: June 04, 2009, 06:09:02 PM »
      read perldoc perldsc

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Generate All 17,576 combinations for 3 alpha places
      « Reply #6 on: June 04, 2009, 07:36:42 PM »
      well... considering how much shorter the perl version is to my VB version (notwithstanding my VB version doesn't even work properly). Turns out my BCScript can churn this out pretty easily, too!

      Code: [Select]
      STORE(X,CHR(SEQ(X,X,65,65+25)))
      STORE(Y,flatten(X+X+X))

      I wish my assignment operators worked. would make that look less messy.
      I was trying to dereference Null Pointers before it was cool.

      gh0std0g74



        Apprentice

        Thanked: 37
        Re: Generate All 17,576 combinations for 3 alpha places
        « Reply #7 on: June 04, 2009, 08:22:11 PM »
        what's BCscript ? never heard of it.

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: Generate All 17,576 combinations for 3 alpha places
        « Reply #8 on: June 04, 2009, 08:45:50 PM »
        Of course not, I haven't released it yet  ;D
        I was trying to dereference Null Pointers before it was cool.

        gh0std0g74



          Apprentice

          Thanked: 37
          Re: Generate All 17,576 combinations for 3 alpha places
          « Reply #9 on: June 05, 2009, 01:49:38 AM »
          what can it do?

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: Generate All 17,576 combinations for 3 alpha places
          « Reply #10 on: June 05, 2009, 09:19:20 AM »
          I'm still exploring that myself, actually  :P , it basically started as a Expression evaluator for use in my programs- but the way I had it structured, I was able to simply add statement separators for the ability to treat it as a script language.


          Right now, it's not exactly a "secure" script language like VBScript, in that it can access  the filesystem (through either the filesystemObject or my BCFile library) as well as the ability to call DLLs, a feature which was not easy to implement, let me tell you!


          Basically, after I had the basics down, I wanted to make it easier to perform calculations- so I made an "SEQ" function, that created an array (or, in BCScript terms, a "List") of numbers. the CHR$() function, as implemented by the Evaluator, doesn't support arrays. However, the Evaluator notices this, and instead performs the function for each element, creating a new element for each one. (Actually, it does this for any function with a single argument that doesn't have certain flags set)

          The same holds true for most operators- including the + operator. the evaluator, again, notices that it will not be able to simply tell VB to add the two together, so it essentially permutes both arrays, using that operator. For example:

          Code: [Select]
          {1,2,3}*{6,7,8}


          gives me:

          {{6,7,8},{12,14,16},{18,21,24}}

          or, a three element array of three element arrays- a matrix, of sorts. Because I found I often wanted to work with these types of results as a single scalar array, I created the "flatten" function which- flattens the array into a one-dimensional array. In the previous output, running the flatten function would result in:


          {6,7,8,12,14,16,18,21,24}

          Originally, I was working with a evaluator I had found on the net, and trying to change it. It was full of hacks and kludges. I eventually lost the code, so I started from scratch, knowing exactly what I wanted- a plugin based architecture for both operators and functions. It worked- once I had the framework down, it became quite a fun endeavor to think of new operators and functions. I quickly added all sorts of operators from a number of programming languages, such as "in" from delphi and pascal, the spaceship operator from Perl, etc etc. And from there it was a simple step to add a statement separator. I already had a robust "variables" and "Functions" collections that were easily programmable from the host program.

          the only downside keeping me from releasing it with too much enthusiasm is my lack of documentation.
          I was trying to dereference Null Pointers before it was cool.