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 .
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 .