i cant figute out how to make my code work the way i want it to.
make() gets me all the combination with a string of length k using a specific dataset. each char in dataset is meant to occurr 0 to k times in any relative position to the other elements in dataset. So, its like a password-list generator.
The problem is that if i let it create f.ex. a 10 digit password vector with dataset "01234567879" there are 10^10 combinations * 10Bytes/Password means
a 100GB of random access memory usage and thus is not suitable in this case and, surely throws bad_alloc().
#include <iostream>
#include <string>
int main ( ) {
std::string foo = "123";
int used[3] = { 0, 0, 0 };
int carry = 0;
while ( carry == 0 ) {
std::cout << foo[used[0]] << foo[used[1]] << foo[used[2]] << std::endl;
carry = 1;
for ( int i = 2 ; i >= 0 ; i-- ) {
used[i] += carry;
if ( used[i] == 3 ) {
used[i] = 0;
carry = 1;
} else {
carry = 0;
}
}
}
}
gives me the combinations from 1, 2 or 3. but i need to get a combination like that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
foo = "01234"
used = length 3 (not the same length than foo is.
i need it to take every item of foo and create a permutation with that)
out:
000
001
002
003
004
010
...
443
444
> This is why i cant figure out how to solve this
You've got to replace all the 2's and 3's and anything else which specifically assumes a string length of 3 with something more appropriate.
It's a hack code to show you the concept.
Not something you can copy/paste without having to do any more thinking.