Yeah well Scooby Doo can do-do, but Jimmy Carter is smarter.
Here's my C++ implementation of the function isodd
bool isodd (int i)
returns true if i is an odd integer, false otherwise
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.Code: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); }
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 .
Last edited by baseline bum; 11-23-2004 at 07:25 PM.
Yeah well Scooby Doo can do-do, but Jimmy Carter is smarter.
Which one of those minimized programs on your start bar is the porn on?
wow, I'm in Comp Sci AP and that's the first C++ code I've ever seen. Looks like Java.
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.
Where the is Ducks when you need him?
not nice to be mean to someone for being smart and understanding something that you never will.
Geek Alert!!! Geek Alert!!!
I don't think it qualifies as an algorithm for odd numbers because it is very unlikely to ever return an answer.
If Bogo Sort can be an algorithm, this one can't?![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)