7 kyu
Power of two
46 of 25,695yuriy.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 | 37641 |
Total Skips | 2465 |
Total Code Submissions | 120683 |
Total Times Completed | 25695 |
Ruby Completions | 1622 |
JavaScript Completions | 14106 |
Python Completions | 6409 |
Haskell Completions | 464 |
C# Completions | 933 |
C Completions | 969 |
TypeScript Completions | 551 |
PureScript Completions | 46 |
Rust Completions | 668 |
Julia Completions | 66 |
NASM Completions | 92 |
COBOL Completions | 14 |
Java Completions | 681 |
Total Stars | 275 |
% of votes with a positive feedback rating | 90% of 2242 |
Total "Very Satisfied" Votes | 1862 |
Total "Somewhat Satisfied" Votes | 314 |
Total "Not Satisfied" Votes | 66 |