Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Can this function be optimized?

Name: Anonymous 2009-05-18 8:52


int SEED = 9000;
int result = 17;
result = (SEED * result) + A;
result = (SEED * result) + B;
result = (SEED * result) + C;
return result;


->

return 9000 * (9000 * ((9000 * 17) + C) + B) + A;

Now what?

Name: Anonymous 2009-05-18 8:55

over 9000 amirite ?

Name: Anonymous 2009-05-18 9:06

>>2
Not really, it depends on the values of A,B,C...

It should be:

return S * (S * ( (S * 17) + A) + B) + C;

Name: Anonymous 2009-05-18 11:17

No amount of rearranging is going to affect how fast it actually runs. Assuming you have a decent compiler, any of the variations above will run in pretty much the same amount of time.

If you want to "optimize" the number of lines of code the section uses, then clearly you can get anywhere between one and six lines, depending on how readable you decide you want it to be.

Don't change these.
Name: Email:
Entire Thread Thread List