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

1. ## best algoritm for generating all possible letter/number combinations

see topic nuff said

2. do you want a random set or every single set??

3. every single set and in alphabetical order...

4. 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. Um, you realize that there are an infinite number of letter/number combos?

6. 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. 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. 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. 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. 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. 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.