PWNED

Jan 22, 2002 01:45

Dimm has to write some proggie for his sped CS class that reverses a number, such that if 1234 were entered, 4321 would be returned. Dimm had some bloated implementation using loops that he dug up from his Trumbo days, but I think I just wrote a more eloquent (if not obfuscated) version:
int ReverseNumber(int n)
{
if(n < 10)
return(n);
else
return((n%10)*pow(10, int(log10(n))) + ReverseNumber(n/10));
}
What do you think? (::looking in Pete's direction::) It isn't the most efficient algorithm, but it sure as hell brings a tear to my eye. Oh, and it has to be written in C++, so no PERL h4x0ring. I guess the next step would be to only use bitwise operations.
Previous post Next post
Up