PDA

View Full Version : Eureka! I've discovered the worst possible algorithm in all of computer science!



baseline bum
11-23-2004, 07:15 PM
Here's my C++ implementation of the function isodd

bool isodd (int i)
returns true if i is an odd integer, false otherwise



bool isodd (int i)
{
if ( i == 0 )
return true;

int k = ( i < 0 )? -1 : 1;

srand (time (0));
/* to make as many cache
* misses as possible
* while also adding
* an exponential series
* of recursive calls
*/
int m = round ( ( double (rand ()) / double (RAND_MAX + 1)) * double (RAND_MAX) );
if ( isodd (m))
return ! isodd (-i + k);
else
return ! isodd (i - k);
}


The stack size would have to be infinite for this function to ever have a chance to return a value for anything other that 0 unless all calls to rand are zero.

I gotta apply to Microsoft and begin work on Longhorn immediately!

The operation count in one iteration (N>0) is:
f[N] = R f[R] + f [N-1]
where R is a random integer between 0 and RAND_MAX (a value guaranteed to be at least 32768) with expected value RAND_MAX/2

of course, f[R] = R1 f[R1] + f[R-1] where R1 is another random variable with the same distribution as R

It logically works though, since it inches toward zero one number per iteration .

Duff McCartney
11-23-2004, 07:25 PM
Yeah well Scooby Doo can do-do, but Jimmy Carter is smarter.

baseline bum
11-23-2004, 07:43 PM
http://www.bol.ucla.edu/~clee1750/blowme.gif

Useruser666
11-23-2004, 08:12 PM
:lol

Which one of those minimized programs on your start bar is the porn on?

Spurbanana
11-24-2004, 12:16 AM
wow, I'm in Comp Sci AP and that's the first C++ code I've ever seen. Looks like Java.

E20
11-24-2004, 12:43 AM
Are you a programmer BB or are you taking classes. Interesting stuff. I was really interested in becoming a game designer before I started watching Basketball.

Guru of Nothing
11-24-2004, 12:48 AM
Where the fuck is Ducks when you need him?

Drachen
11-24-2004, 04:01 AM
not nice to be mean to someone for being smart and understanding something that you never will.

DrRich
11-24-2004, 08:46 AM
Geek Alert!!! Geek Alert!!!

spurster
11-24-2004, 09:02 AM
I don't think it qualifies as an algorithm for odd numbers because it is very unlikely to ever return an answer.

baseline bum
11-24-2004, 12:17 PM
If Bogo Sort can be an algorithm, this one can't? :(