> perhaps 1000 chars, so I need something scalable to multiple cores/cpus.
Try doing the maths first.
Each character you add to the length of the string DOUBLES the amount of time it takes.
If you were blindingly efficient in your code, and could permute every 1nS (a handful of instructions on the fastest processors), you could do a string of 30 characters.
The next 30 chars would take about 30 YEARS to get through.
61 chars -> 60 years
62 chars -> 120 years (are you still interested?)
Or each char DOUBLES the number of machines you need to solve the problem. There isn't enough sand to make enough processors to make any significant dent in this problem.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
I recently did something similar to help me solve a knapsack problem. You may be interested in my java method here which can take a string of 0s and 1s and generate the next subset value. So basically, just pass it the initial string of all 0s(the empty subset) and use this method in a loop to generate all possible permutations.
public static String nextSubset(String subset) {
//Step 1 (initialization)
StringBuffer buffer = new StringBuffer(subset);
int k = buffer.length();
// Step 2 (look for rightmost 0)
while((k >= 1) && (buffer.charAt(k - 1) == '1') ) {
k--;
}
// Step 3 (if there is a zero, form the next string)
if(k >= 1) {
buffer.setCharAt(k - 1, '1');
for(int j = k + 1; j <= buffer.length(); j++) {
buffer.setCharAt(j - 1 , '0');
}
return buffer.toString(); }
else
return buffer.toString();
}
sloan31
Junior Poster in Training
65 posts since Apr 2008
Reputation Points: 14
Solved Threads: 3
Adak
Nearly a Posting Virtuoso
1,479 posts since Jun 2008
Reputation Points: 425
Solved Threads: 185