Thread: best algoritm for generating all possible letter/number combinations

  1. #1
    Unregistered
    Guest

    best algoritm for generating all possible letter/number combinations

    see topic nuff said

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    do you want a random set or every single set??

  3. #3
    Unregistered
    Guest
    every single set and in alphabetical order...

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    I think that u would use nested for loops with numbers and comvert the numbers into the corresponding ascii character. not too sure if this would work because I am not familiar with the ascii character codes.

  5. #5
    Registered User JTtheCPPgod's Avatar
    Join Date
    Dec 2001
    Posts
    44
    Um, you realize that there are an infinite number of letter/number combos?
    "No! I must have my delicious cupcakes, my sweet cakey treasures, piping hot from their 40 watt WOMB!!!"
    --Captain Murphy

  6. #6
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    As far as I know, due the fact JTtheCPPgod pointed out there is no "best" algorithm. Perhaps add some restrictions like length. Then the job becomes a little bit easier.

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    This code will print out all possible permutations of the string input

    Code:
    #include <iostream> //for cout
    #include <string>  //for string
    #include <algorithm> //for next_permutation
    
    using namespace std;
    
    int main()
    {
    string input = "abcdef";
    while( next_permutation( input.begin() , input.end() ) )
    {
       cout << input << endl;
    }
    return 0;
    }
    The input string must be sorted in value from lowest to highest (ascii value ) You can use the sort function if you need to sort the input

  8. #8
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    I was assuming that there was a set length that was desired. If not, then ur program will never even finish its first set

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    Originally posted by golfinguy4
    I was assuming that there was a set length that was desired. If not, then ur program will never even finish its first set
    Are you refering the code i posted? The next_permutation calculates the next highest permutation of the data you send it, using the < operator. so the permutation 012 is less than 102 which is less than 210.
    Once it get to the final permutation it will return false and exit the loop

  10. #10
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You will have to set a length on your string. Then there is a finite amount of permutations. For instance if you want to find out how many combos of numbers there are in 5 numbers ranging from 0 to 100 you would do this:

    100*99*98*97*96*95.

    This assumes that no number can be repeated in the sequence.

    Otherwise it would be 100*100*100*100*100.

    So if you have 52 letters (26 uppercase and 26 lowercase) and ten numbers you have 62 total characters to choose from. Assuming you want 10 values in the sequence (non-repeating) you would do 62*61*60*59*58*57*56*55*54*53*52 or 62!-52!.

    So for non repeating sequences the equation is

    MaxNum!-((MaxNum-NumberOfValues)!)

  11. #11
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    I wasn't talking about ur code RPImatty. I was saying that if he wanted every possible set of characters and numbers without using an input, he would have to create a set length or the program would never finish with the first item.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Combinations
    By Cmuppet in forum C Programming
    Replies: 6
    Last Post: 10-19-2004, 07:39 AM
  2. Grabbing Ctrl and Alt key combinations
    By scorpio_IITR in forum Linux Programming
    Replies: 0
    Last Post: 04-12-2004, 03:01 AM
  3. Combinations, lotto, 6/49
    By Robert in forum C++ Programming
    Replies: 8
    Last Post: 12-06-2002, 07:27 PM
  4. Combinations
    By GaPe in forum C Programming
    Replies: 16
    Last Post: 01-09-2002, 05:38 AM