|
|
|
|
|
by pyre
5886 days ago
|
|
I would consider the mod operator to be pretty basic though. (Feel free to call me out if I'm just being naive.) 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) == result
|
|
In an interview you could explain your reasoning for such a detour as well, which might work out better than just "knowing the answer."