7 kyu
Cyclops numbers
1,418 of 2,610Nmistrata
Description:
A cyclops number is a number in binary that is made up of all 1's, with one 0 in the exact middle. That means all cyclops numbers must have an odd number of digits for there to be an exact middle.
A couple examples:
101
11111111011111111
You must take an input, n, that will be in decimal format (base 10), then return True if that number wil be a cyclops number when converted to binary, or False if it won't.
Assume n will be a positive integer.
A test cases with the process shown:
cyclops (5)
"""5 in biinary"""
"0b101"
"""because 101 is made up of all "1"s with a "0" in the middle, 101 is a cyclops number"""
return True
cyclops(13)
"""13 in binary"""
"0b1101"
"""because 1101 has an even number of bits, it cannot be a cyclops"""
return False
cyclops(17)
"""17 in binary"""
"0b10001"
"""Because 10001 has more than 1 "0" it cannot be a cyclops number"""
return False
n
will always be > 0
.
Algorithms
Similar Kata:
Stats:
Created | Feb 2, 2016 |
Published | Feb 2, 2016 |
Warriors Trained | 4381 |
Total Skips | 64 |
Total Code Submissions | 13020 |
Total Times Completed | 2610 |
Python Completions | 1418 |
Ruby Completions | 163 |
C Completions | 120 |
JavaScript Completions | 779 |
Java Completions | 210 |
Total Stars | 54 |
% of votes with a positive feedback rating | 94% of 454 |
Total "Very Satisfied" Votes | 406 |
Total "Somewhat Satisfied" Votes | 41 |
Total "Not Satisfied" Votes | 7 |