27
2
A positive integer N is K-sparse if there are at least K 0s between any two consecutive 1s in its binary representation.
So, the number 1010101 is 1-sparse whereas 101101 is not.
Your task is to find the next 1-sparse number for the given input number. For example, if the input is 12 (0b1100
) output should be 16 (0b10000
) and if the input is 18 (0b10010
) output should be 20 (0b10100
).
Smallest program or function (in bytes) wins! Standard loopholes disallowed.
“next” as in “next highest” or as in “with least absolute difference” ? – FUZxxl – 2015-04-02T12:17:29.773
"next" as in "next highest". – articuno – 2015-04-02T12:21:43.890
What range of input needs to be handled? – mbomb007 – 2015-04-02T19:38:45.627
I'm going to assume negative numbers don't need to be. – mbomb007 – 2015-04-02T19:53:50.373
@articuno Can we create a function, or does it have to be a full program? Functions are pretty standard. – mbomb007 – 2015-04-03T02:35:41.833
@mbomb007 you can use standard functions – articuno – 2015-04-03T02:46:30.127