On a bad day can't solve some of those interview problems. (and I think of myself as an average coder although I try to mitigate that handicap by building from the ground up and testing those components well)
If your language doesn't do integer division that way, the naive approach is even easier if you know how to round: x / y == round(x / y) iff x % y == 0.
There are many, many other approaches which will work, too. I saw one guy hand-build an array of ints, initialize to zero, loop over it once with arr[i++] = 0; arr[i++] = 0; arr[i++] = 3 to set the multiples of 3, then do the same thing with the fives except checking to see if there was already a 3 there, then looping over the array a fourth time to handle the actual printing.
That is the kind of competent, worksmanlike programming that runs the world while the can't-do-FizzBuzz guys are hopefully not touching the code too much.
Outside of the mod operator, you could always use a combo of floor() and ceiling() (which I assume most languages have in a standard library). e.g.:
from math import floor,ceil
def divisible_by_3(n):
result = n / 3.0
return ceil(result) == floor(result)
Or even more basic: def divisible_by_3(n):
result = n / 3.0
return int(result) == resultIn an interview you could explain your reasoning for such a detour as well, which might work out better than just "knowing the answer."
var s = require('sys');
for (var i = 1; i < 101; i++) {
if (i%3 == 0 && i%5 == 0) s.puts('fizzbuzz');
else if (i%3 == 0) s.puts('fizz');
else if (i%5 == 0) s.puts('buzz');
else s.puts(i);
}
node.fizzbuzz.jsIf you can't understand how this can happen you need to read The Peter Principle.