I want to generate string of given length, from given characters. The order of the characters matters, also I want to use multiple threads to generate it. Here are a few examples:
chars: a,b,c,d
length: 1
output:
a
b
c
d
chars: a,b,c,d
length: 2
output:
aa
ab
ac
ad
bb
ba
bc
bd
cc
ca
cb
cd
dd
da
db
dc
I've tried this algorithm: Note: it's pseudo-code
func generate(set, str, k){
if (k == 0){
print str;
return;
}
for (c in set) {
newString = str + c;
generate(set, newString, k-1);
}
}
However I don't see how to use multiple threads. All other algorithms I've read about don't suite my needs.