4 ms·
I think his first example was a recursive function like: if !(mod(x,2) { if (x == 1) return true else return false; }else return is_power_of_2(x/2); o
by Retric 16y ago
I think his first example was a recursive function like:
if !(mod(x,2) {
if (x == 1) return true else return false;
}else return is_power_of_2(x/2);
or
if !(mod(x,2) {
if (x == 1) return true;
if ((x > 1) || (x == 0)) return false;
return is_power_of_2(x * 2);
}else if (x > 2) return is_power_of_2(x/2) else return false;
PS: 2^0 = 1 and 2^-1 so you could have 3 versions of this fuction.