Hello there...
I'm legolizard, and I've been watching the tek syndicates' videos for a while now, and thought it would be a good idea to finally join the forum. :D It really is awesome, I must say...
I was wondering if anyone could help with an algorithm I'm designing. It's mainly for the giggles. I mean, who doesn't like seeing lines and lines of numbers strung across the console window in an endless furry of some computational mess?
I've written this program in C++; it is relatively simple, yet I wish to optimize it so that it will output the answer faster. To outline the basic goal of the program:
Find all the differnt series of numbers that are the summation of a set number, n. For example, assuming the user enters in five the ouput would be:
1 4
2 3
5
For small n my current method is super fast, but that's not much of an accomplishment, lawl. For n > 40 the process can take up to a minute+.
Could anyone offer some advice on how to optimize my current method?
My current function:
void getSums( const std::string &str, int x, int y ){
for( ; x >= 2 * y + 1; y++ ) getSums( str + ' ' + toString(y), x - y, y + 1 );
std::cout << str << ' ' << x << std::endl;
}
I know that seems kind of... weird at first, I asked my CS teacher and he gave me ?_? face. It really isn't all too complicated though... at least from my point of view it isn't... then again I spent days thinking about it, lawl.
toString is a function I declared earlier in the program to parse an integer data type to a string(Templates ftw).
Any help would be appreciated. Thanks. :D Oh and thanks for this awesome forum. ^_^