3 ms·
You can solve fizbuzz without modulo operator: bool divisible_by(int a, int b) { return a==((a/b)*b); } It doesn't require anything more than kn
by ajuc 13y ago
You can solve fizbuzz without modulo operator:
bool divisible_by(int a, int b) {
return a==((a/b)*b);
}
It doesn't require anything more than knowledge about what division means, and I think it's fair play to require such knowledge from programmers.
- Houshalter 13y agoMaybe this is a stupid question, but wouldn't that always return true? (a/b)*b just cancels out the b right? Unless there is weird floating point stuff going on.
- Dylan16807 13y agoOr even if you don't know anything about integer math, you can use repeated subtraction. Or ask for help on finding a multiple and do the rest of the structure yourself. Or keep a counter to 3 and a counter to 5 and reset them when they fill up. Definitely not a gimmick question about whether you know about modulus.