30
2
Task
Find the set of numbers such that the binary representation contains two or more runs of 1
separated by at least one 0
.
For example, the for the numbers that are 4 bits long:
0 0000 (no ones)
1 0001 (only one run)
2 0010 (only one run)
3 0011 (only one run)
4 0100 (only one run)
5 0101 Valid
6 0110 (only one run)
7 0111 (only one run)
8 1000 (only one run)
9 1001 Valid
10 1010 Valid
11 1011 Valid
12 1100 (only one run)
13 1101 Valid
14 1110 (only one run)
15 1111 (only one run)
Input
An integer provided to the application via some input in the range 3 .. 32
. This represents the maximum number of bits to count up to.
The input of n
indicates that the numbers 0 .. 2n-1
need to be examined.
Output
A delimited (your choice) list of all numbers meeting the criteria. The numbers are to be presented in numeric order. An extra trailing delimiter is acceptable. Data structure enclosures (e.g. []
and similar) are also acceptable.
Example
Input: 3
Output: 5
Input: 4
Output: 5, 9, 10, 11, 13
Input: 5
Output: 5, 9, 10, 11, 13, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 29
This is code-golf - the answer with the least amount of bytes wins.
I think you missed 23 for n=5. – xnor – 2015-10-21T21:02:26.557
@xnor you are correct. Thank you, and yep, that also makes it not equivalent to A094695. Hmm. https://oeis.org/A101082 vs https://oeis.org/A166934
– None – 2015-10-21T21:03:42.113@VTCAKAVSMoACE yes. If one is
\n
delimiting and putting a\n
on the last line, then,
delimited with a,
trailing should be acceptable too. Updated. – None – 2015-10-21T21:24:48.2231Can the input be in a list format like
[1, 2, 3]
? – kirbyfan64sos – 2015-10-21T22:33:48.320@kirbyfan64sos yes. Updated. – None – 2015-10-21T23:11:33.293
Does the output have to be sorted? – kirbyfan64sos – 2015-10-21T23:18:34.833
@kirbyfan64sos yes: "The numbers are to be presented in numeric order." – None – 2015-10-21T23:19:16.110
@ThomasKwa that is really a matter of the implementation. If you are providing code, it should run somewhere correctly (see the bit about specific python implementation in comments).
– None – 2015-10-22T13:12:04.900Are we allowed to exit with an error after the output is generated? – lirtosiast – 2015-10-23T05:48:09.270
@ThomasKwa good and interesting question. I'm going to have to go with "I'm really only concerned about the output" and so to your question, yes, it may exit with an error after the output is generated. – None – 2015-10-23T15:49:40.857