67
1
Task:
Given an integer input, figure out whether or not it is a Cyclops Number.
What is a Cyclops number, you may ask? Well, it's a number whose binary representation only has one 0
in the center!
Test Cases:
Input | Output | Binary | Explanation
--------------------------------------
0 | truthy | 0 | only one zero at "center"
1 | falsy | 1 | contains no zeroes
5 | truthy | 101 | only one zero at center
9 | falsy | 1001 | contains two zeroes (even though both are at the center)
10 | falsy | 1010 | contains two zeroes
27 | truthy | 11011 | only one zero at center
85 | falsy | 1010101 | contains three zeroes
101 | falsy | 1100101 | contains three zeroes
111 | falsy | 1101111 | only one zero, not at center
119 | truthy | 1110111 | only one zero at center
Input:
An integer or equivalent types. (
int
,long
,decimal
, etc.)Assume that if evaluating the input results in an integer overflow or other undesirable problems, then that input doesn't have to be evaluated.
Output:
Truthy or falsy.
Truthy/falsy output must meet the used language's specifications for truthy/falsy. (e.g. C has
0
as false, non-zero as true)
Challenge Rules:
Input that is less than 0 is assumed to be falsy and thus does not have to be evaluated.
If the length of the binary representation of the number is even, then the number cannot be a Cyclops number.
General Rules:
This is code-golf, so the shortest answers in bytes wins!.
Default loopholes are forbidden.
Standard rules apply for your answer with default I/O rules.
This is my first Programming Puzzles & Code Golf challenge, so any feedback on how I should improve would be much appreciated!
25
Note: This is A129868
– tsh – 2019-03-08T02:40:27.54735+1 for the 2800 year late pop culture reference in the title – Sanchises – 2019-03-08T09:21:52.693
what is the maximum number that is be tested? – Serverfrog – 2019-03-08T13:06:45.897
@Serverfrog since I did not specify a limit, assume that any positive integer can be tested. – Tau – 2019-03-08T14:09:07.943
Is binary input allowed? – Qwertiy – 2019-05-25T08:22:30.913