7 kyu
Power of two
46 of 25,886yuriy.tsemashko
Description:
Complete the function power_of_two
/powerOfTwo
(or equivalent, depending on your language) that determines if a given non-negative integer is a power of two. From the corresponding Wikipedia entry:
a power of two is a number of the form 2n where n is an integer, i.e. the result of exponentiation with number two as the base and integer n as the exponent.
You may assume the input is always valid.
Examples
powerOfTwo 1 `shouldEqual` true
powerOfTwo 2 `shouldEqual` true
powerOfTwo 6 `shouldEqual` false
powerOfTwo 8 `shouldEqual` true
powerOfTwo 1024 `shouldEqual` true
powerOfTwo 1026 `shouldEqual` false
Beware of certain edge cases - for example, 1
is a power of 2
since 2^0 = 1
and 0
is not a power of 2
.
Mathematics
Algorithms
Fundamentals
Similar Kata:
Stats:
Created | Apr 15, 2014 |
Published | Apr 15, 2014 |
Warriors Trained | 37853 |
Total Skips | 2480 |
Total Code Submissions | 121380 |
Total Times Completed | 25886 |
Ruby Completions | 1623 |
JavaScript Completions | 14180 |
Python Completions | 6474 |
Haskell Completions | 465 |
C# Completions | 946 |
C Completions | 974 |
TypeScript Completions | 559 |
PureScript Completions | 46 |
Rust Completions | 673 |
Julia Completions | 66 |
NASM Completions | 95 |
COBOL Completions | 14 |
Java Completions | 700 |
Total Stars | 278 |
% of votes with a positive feedback rating | 90% of 2250 |
Total "Very Satisfied" Votes | 1867 |
Total "Somewhat Satisfied" Votes | 316 |
Total "Not Satisfied" Votes | 67 |