One of the Bloomberg interviewers asked me a question about a year ago I've never been able to figure out. Compute the logarithm (base 10) of a number with basic math operators. I can't recall if it was specified whether the inputs or outputs were to be rounded to integers or not.
I told them the best I could do was a solution that worked for exact powers of 10:
Code:
int log10(int input)
{
int log = 0;
while (input /= 10)
log++;
return log;
}
And that I had no clue about the requisite algorithm of how to compute log10 of, for instance, 5000. And I still don't. I told them, this is not a coding problem, per se; if I knew the algorithm, I'm sure I could write the necessary code.
In retrospect, I could have suggested a linear approximation between the 1000->3 and 10000->4 or something, but I doubt they would have liked that answer anyway, since it seems like it would be pretty terrible, mathematically speaking.