Maybe that's not the best title, but it's close. What I'm looking to do is pull a set number of characters from 3 different arrays, and then run permutations on them, and then pull a different set of characters from the arrays and run permutations on those. On and on until every set of characters has been run against all others to hit every possible permutations with the specified number of characters from each array. I do test each permutation before the next one is computed.
So far I can only hit some of that. I can pull a certain number of characters that change, but I can't figure out how to hit every permutation of characters within the array.
My 3 arrays are capital letters, lower case letters, and numbers. So say I want 3 upper, 2 lower, and 1 number. I would want it to pick ABCab0 and run every permutation. Then ABDab0, ABEab0, ... , ABCac0, ABDac0, ... , ABCab1, ... XYZyz9.
Yes, I know this will take a large amount of time to run through all of this.
This is currently what I'm using:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
int i,j = 0;
int nn = 1;
int ln = 3;
int un = 2;
string l = "abcdefghijklmnopqrstuvwxyz";
string u = "ZYXWVUTSRQPONMLKJIHGFEDCBA";
string n = "0123456789";
do {
string a = l.substr(i, ln);
string b = u.substr(i, un);
string c = n.substr(j, nn);
string s = a + b + c;
sort(s.begin(), s.end());
do {
//permutation test
}
} while (next_permutation(s.begin(), s.end()));
j++;
i++; //stops it after success with an error
if (j == 6)
j = 0;
}
while ( i <= (26-un));
|
Edit: I'm not very good at coding, I understand it enough to piece together other codes and make them work for what I need. This piece is mostly my own and that is why it is probably not efficient/has n00b mistakes.