appacademy / prep-work

preparatory material for interviewing with App Academy
291 stars 339 forks source link

is_power_of_two? #82

Open mluu510 opened 8 years ago

mluu510 commented 8 years ago

so i tried out the solution to is_power_of_two? with is_power_of_two?(9), it returns false. is this a bug in the code?

jaysonvirissimo commented 8 years ago

It's my understanding that 'power of two' refers to a number that can be expressed in the form 2^n, where n is an integer (such as 2^5 or 32). You may be thinking of a square number, which has the form x^2, where x is an integer (like 3^2 or 9). The difference is that, in the former, the base is 2, while in the later, the exponent is 2.

Does that make sense?