g | x | w | all
Bytes Lang Time Link
047Zsh241113T022743Zroblogic
078C241115T040448ZNoLonger
00705AB1E241114T144848ZKevin Cr
012Japt241112T112421ZShaggy
008Vyxal 3 R241112T175011Zpacman25
011iogii241112T170920ZDarren S
051JavaScript Node.js241112T091113Zl4m2
096C151022T053759ZJerry Je
007Thunno 2230825T103323ZThe Thon
010Jelly190826T032150ZUnrelate
028k4190825T185732Zscrawl
060JavaScript ES6190825T200743Zfəˈnɛtɪk
099C gcc151022T000041ZG. Sliep
110Java151021T210911Zuser1893
081C151027T102147ZAlchymis
102C151026T233908Zchqrlie
nan151023T115505ZAbr001am
030TIBASIC151022T151825Zlirtosia
nan151023T154701ZAbr001am
053Haskell151022T152524ZXwtek
044Python151023T124956ZCutwell
080PowerShell151023T082140ZAndrew
062JavaScript ES7151021T213159ZETHprodu
062JavaScript ES6151022T173948ZMwr247
019K5151022T205451ZJohnE
041Julia151021T221702ZAlex A.
027APL151021T224150ZAlex A.
041Perl 5151021T222145Zmsh210
141C++151021T221001Zuser1893
040Julia151022T132454ZGlen O
014CJam151021T214136Zaditsu q
089Python 2.7151021T205559Zxenia
012Pyth151021T231619ZDennis
nanPip151022T020948ZDLosc
076JavaScript ES6151022T004433Zedc65
016Pyth151021T222625Zkirbyfan
048Python151021T211234Zxnor
047R151021T222448ZDavid Ar
038Ruby151021T204929ZDoorknob
059Matlab151021T210239Zflawr

Zsh, 57 51 49 47 bytes

-2 bytes: thanks to @GammaFunction

for i ({0..$[2**$1]})${$(([##2]i))/*01*}&&<<<$i

Try it online!   49b 51b 57b

C, 78 bytes

long i,j;main(){for(scanf("%ld",&j);!(++i>>j);)i&-~(i|~-i)&&printf("%ld ",i);}

Based on @Alchymist's entry, but uses slightly different techniques.

An irrelevant change is that the test is !(++i>>j) instead of ++i<1L<<j, as both tests are nine bytes long.

The main change is that the test has been changed from (x|x-1) & (x|x-1)+1 to x&(x|x-1)+1. This takes no fewer bytes except that it doesn't need an extra variable to hold the common subexpression. (I also express adding 1 with -~ and subtracting 1 with ~-, which are equivalent on integers but bind much more tightly, not that it matters here.

05AB1E, 8 7 bytes

oLʒb01å

-1 byte porting @xnor's first Python approach

Try it online or verify all test cases.

Original approach (8 bytes):

oLʒbÔSO≠

Try it online or verify all test cases.

Explanation:

o        # Push 2 to the power of the (implicit) input-integer
 L       # Pop and push a list in the range [1,2**input]
  ʒ      # Filter this list by:
   b     #  Convert the current value to a binary-string
    01å  #  Check whether it contains "01"
         # (after which the filtered list is output implicitly)
    Ô    #  Connected-uniquify the bits in the binary-string
     SO  #† Sum the amount of remaining bits together
       ≠ #  Check that it's NOT 1
         #  (hence why we created a list in the range [1,...] instead of [0,...])
         # (after which the filtered list is output implicitly)

The b...SO (S = convert string to list of characters; O = sum bits) could be a few different alternatives for the same byte-count, like b...1ö (convert binary-string from base-10 to base-1, which sums its digits); b...1¢ (count the amount of 1s in the binary-string); or 2в...O (use a binary-list instead of binary-string, and simply sum it after the connected-uniquify).

Japt, 12 bytes

2pU Ǥø2¤ÔÃð

Try it

2pU Ǥø2¤ÔÃð     :Implicit input of integer U
2pU              :2 to the power of U
    Ç            :Map the range [0,2pU)
     ¤           :  To binary string
      ø          :  Contains?
       2¤        :    2 to binary string
         Ô       :    Reverse
          Ã      :End map
           ð     :0-based truthy indices

Vyxal 3 -R, 8 bytes

EΩbġ…∑1>

Vyxal It Online!

doesn't use the binary string trick

Vyxal 3 -R, 7 bytes

EΩbo1zc

Vyxal It Online!

this one does sort of

iogii 11 bytes

^}:2D:t<#v2

Try it!

Or more verbosely:

2 $ pow countTo dup 
2 toBase dup tail < sum
filter

iogii is postfix syntax and all of those ops are just regular ops. Rotation trick was used to place the arg ($) implicitly.

It looks for "01" by doing a vectorized "<" with the binary digits and the tail of the binary digits (sum is used to look for at least 1).

JavaScript (Node.js), 51 bytes

a=>[...Array(1<<a).keys()].filter(y=>(y+=y&-y)&y-1)

Try it online!

C 96

Thanks to @ceilingcat for making it much shorter

x,c;main(n,v){for(n--;c<1<<n;c++)for(v=0;v<32&&!(c>>v&x<v&&x&&printf("%d ",c));)x=c&1<<v++?v:x;}

Try it online!

Thunno 2, 7 bytes

OLæḃkdƇ

Try it online!

Explanation

OLæḃkdƇ  # Implicit input
OLæ      # Filter range(2**input) by:
   ḃkdƇ  #  Binary contains "01"?
         # Implicit output

Jelly, 10 bytes

2*’BŒgṫɗƇ3

Try it online!

Translated from Dennis' Pyth solution.

        Ƈ     Filter the range from 1 to
2*’           2^input - 1
   B   ɗ      for elements the binary representations of which,
    Œg        when split into runs,
      ṫ  3    are nonempty with their first 2 elements removed.

k4, 32 28 bytes

{&1<+/'1='-':'0b\:'o:!*/x#2}

explanation

                      */x#2   /x^2
                   o:!        /assign o to [0,x^2 -1), e.g. for x=2, o<-0 1 2 3
              0b\:'           /get binary value of each array elem
          -':'                /get delta of adjacent digits in each binary num
    +/'1='                    /sum each array to find how many deltas=1
 &1<                          /return elems where there were greater than 1 deltas=1

JavaScript ES6, 60 bytes

Code

n=>[...Array(1<<n).keys()].filter(g=x=>x>4?x%4==1|g(x>>1):0)

Try it online!

Explanation

[...Array(1<<n).keys()]                                          Create an array of numbers from 0 to 2^n-1
                       .filter(                                  Find the numbers which meet criteria
                               g=x=>x>4?                  :0     If x is less than or equal to four return zero (false/invalid)
                                        x>4?x%4==1|              If the binary pattern ends with 01 return one (true/valid)
                                                   g(x>>1)       Otherwise bitshift right by one and try again

C (gcc), 111 99 bytes

long i,x;main(a,b)char**b;{for(;++i<1L<<atol(b[1]);x>>ffsl(~x)-1&&printf("%ld,",i))x=i>>ffsl(i)-1;}

Try it online!

12 bytes shaved of thanks to @ceilingcat!

Ungolfed:

int main(int a, char **b) {
  for(long i = 0, x = 0; ++i < (1LL << atol(b[1])); ) {
    x = i >> (ffsl(i) - 1);
    if (x >> (ffsl(~x) - 1))
      printf("%ld,", i);
  }
}

The function ffsl() gives you the index of the first bit that is set in a long integer. So we loop from i = 1 to 2^number_of_bits. We set x to i shifted right until we have removed all consecutive zero bits on the least significant end. Then, we shift x right until we have removed all consecutive 1 bits at the least signficant end. If the result is still non-zero, we found a match.

Java, 214 165 155 154 148 141 110 bytes

This submission exploits the fact that a binary string representation of a number in Java never has a leading zero. If the string "01" appears in the binary representation of a number, that must mark the second occurrence of the number "1".

Golfed:

String f(int l){String r="";for(long i=5;i<1L<<l;++i)if(Long.toString(i,2).contains("01"))r+=i+", ";return r;}

Ungolfed:

public class NumbersWithMultipleRunsOfOnes {

  public static void main(String[] a) {
    // @formatter:off
    String[][] testData = new String[][] {
      { "3", "5" },
      { "4", "5, 9, 10, 11, 13" },
      { "5", "5, 9, 10, 11, 13, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 29" }
    };
    // @formatter:on

    for (String[] data : testData) {
      System.out.println("Input: " + data[0]);
      System.out.println("Expected: " + data[1]);
      System.out.print("Actual:   ");
      System.out.println(new NumbersWithMultipleRunsOfOnes().f(Integer.parseInt(data[0])));
      System.out.println();
    }
  }

  // Begin golf
  String f(int l) {
    String r = "";
    for (long i = 5; i < 1L << l; ++i)
      if (Long.toString(i, 2).contains("01")) r += i + ", ";
    return r;
  }
  // End golf
}

Program output (remember, trailing delimiters are acceptable):

Input: 3
Expected: 5
Actual:   5, 

Input: 4
Expected: 5, 9, 10, 11, 13
Actual:   5, 9, 10, 11, 13, 

Input: 5
Expected: 5, 9, 10, 11, 13, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 29
Actual:   5, 9, 10, 11, 13, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 29, 

C, 84 81 bytes

long i,j,k;main(){for(scanf("%ld",&j);++i<1L<<j;k&k+1&&printf("%ld ",i))k=i|i-1;}

This is based on the comments I made on another C answer to this question about the possibility of using simple bitwise operators. It works by switching all trailing 0 bits to 1 in the statement i|(i-1). Then it switches all trailing 1 bits to 0 using k&(k+1). This will result in a zero if there is only one run of ones and non-zero otherwise. I do make the assumption that long is 64-bit but could correct this at the expense of three bytes by using int64_t instead.

Ungolfed

long i,j,k;
main()
{
    for(scanf("%ld",&j);++i<1L<<j;)
    {
        k=i|(i-1);
        if((k&(k+1)) == 0)
            printf("%d ",i);
    }
}

C, 103 102 bytes

long i,x;main(int a,char**b){for(;++i<1L<<atoi(b[1]);)for(x=i;x>4&&(x%4!=1||!printf("%ld,",i));x/=2);}

Expanding (actually contracting) on G.Sliepen entry, taking advantage of xnor remark on the 01 pattern in the binary representation, but using only standard functions and some bit twiddling.

Ungolfed version:

long i, x;
main(int a, char**b) {
    for (; ++i < 1L << atoi(b[1]);) {
        for (x = i; x > 4 && (x % 4 != 1 || !printf("%ld,", i)); x /= 2)
            ;
    }
}

The inner loop scans i for the binary pattern 01 by iteratively shifting x to the right as long as it has 3 bits left. printf returns the number of characters printed, hence never 0, so the inner loop test fails after the printf, avoiding the need for a break statement.

C++, 129 128 bytes

Adapting the same idea, the C++ variant is here:

#include<iostream>
long i,x;int main(int a,char**b){for(;++i<1L<<atoi(b[1]);)for(x=i;x>4&&(x%4!=1||!(std::cout<<i<<','));x/=2);}

Technically, I should make i a long long to ensure 64 bit operation and compute upto 2^32 for an extra 5 bytes, but modern platforms have 64 bit ints.

matlab(90)(70)

j=input('');for l=2:j-1,a=1;for k=l:-1:2,a=a+2^k;a:a+2^(k-1)-2,end,end

execution

4

ans =

5

ans =

9    10    11

ans =

13

principle

Any number taken from the interval ]f(n,l),f(n,l)+2^(l-1)[ where l>1 verifies this condition, so the outcome is a result of the negation of this series in terms of n.

x=1

x=x+1=01,

x=x+2^0=11,

x=x+1=001,

x=x+2^1=011,

x=x+2^0=111,

x=x+1=0001,

x=x+2^2=0011,

x=x+2^1=0111,

x=x+2^0=0111,

x=x+1=1111 ...

x+1, x=x+2^n, x=x+2^(n-1)...x=x+2^0

My program prints the range between each two lines (if exists)


Edit: unfortunately that doesnt make it golfed more but i wanted to add another approach of proceding this idea

after a period of struggle i succeded to find a mathematical representation for this series which is:

2^l(0+1+2^1+...2^k) with l+k < n

=2^l(2^k-1)

score=90

@(n)setdiff(0:2^n-1,arrayfun(@(x)2^mod(x,(n+1)-fix(x/(n+1)))*(2^fix(x/(n+1))-1),0:(n+1)^2))

TI-BASIC, 34 32 30 bytes

For a TI-83+/84+ series calculator.

For(X,5,e^(Ans
If log(sum(2=int(4fPart(X/2^randIntNoRep(1,Ans
Disp X
End

For a number to contain two runs of 1s, it must contain two 10s when we tack a trailing zero onto the binary representation.

Rather than generate the binary representation and check for a 10, we test pairs of bits mathematically by using remainder by 4 (int(4fPart(), which will give 2 where there is a 10. Because we don't care about order, randIntNoRep( is the shortest way to generate the list of exponents.

We use log( to check for the number of runs:

We use e^(Ans as the ending argument of the For( loop—it's always greater than 2^Ans, but e^( is a single token, so it's one byte shorter.

Input/output for N=4:

4:prgmRUNSONES
               5
               9
              10
              11
              13

Then the calculator throws an error; the error screen looks like this:

ERR:DOMAIN
1:Quit
2:Goto

When 1 is pressed, the home screen is displayed again:

4:prgmRUNSONES
               5
               9
              10
              11
              13
           Error

TI calculators store all numbers in a BCD float with 14 digits of precision, not an int or binary float. Therefore, divisions by powers of two greater than 2^14 may not be exact. While I have verified that the trickiest numbers, 3*2^30-1 and 2^32-1, are handled correctly, I have not ruled out the possibility of rounding errors. I would however be surprised if there were errors for any input.

another different matlab answer of good score.

matlab 60(57)

@(n)find(mod(log2(bitcmp(1:2^n,fix(log2(1:2^n)+1))+1),1))

execution

>> @(n)find(mod(log2(bitcmp(1:2^n,fix(log2(1:2^n)+1))+1),1))

ans =

@(n)find(mod(log2(bitcmp(1:2^n,fix(log2(1:2^n)+1))+1),1))

>> ans(5)

ans =

 5     9    10    11    13    17    18    19    20    21    22    23    25    26    27    29

example:

0000111 is rejected because ~x=1111,~x+1=00001 contains one digit=1

0100111 is accepted because ~x=1011,~x+1=0111 contains many 1's

Haskell, 68 61 53 bytes

Improvement from Damien

g x|x`mod`4==1=x>4|2>1=g$x`div`2
a x=filter g[1..2^x]

History:

This fixes the bug(Switched == and =, and square instead of power of two). And replace true with 2>1 and false with 1>2. Also thanks to point out that 2^x is always fail. Thanks to Thomas Kwa and nimi

g x|x<5=1>2|x`mod`4==1=2>1|2>1=g$x`div`2
a x=filter g[1..2^x]

Originally

g x|x<5=False|x`mod`4=1==True|2>1=g$x`div`2
a x=filter g[1..(x^2-1)]

If it have to be full program,

g x|x<5=False|x`mod`4==1=True|2>1=g$x`div`2
main=interact$show.a
a x=filter g[1..2^(read x)]

Python, 44 Bytes

Okay, this could probably be shorter but it's my first codegolf:

x=1
while True:
    if '01' in bin(x):
        print(x)
    x+=1

Think this answers the question, please don't down vote if it doesn't, just post whats wrong with it below.

PowerShell, 80 bytes

while([Math]::Pow(2,$args[0])-gt$n++){$n|?{[Convert]::ToString($n,2)-match"01"}}

JavaScript (ES7), 89 85 72 69 62 bytes

Holy cow, creating ranges in JS is not easy. Perhaps it would be shorter with an actual for loop. Nope, I lied; it's actually a bit longer. Oh well. I guess I'll just have to settle for 27 bytes saved. (7 thanks to Mwr247!)

x=>[for(a of Array(1<<x).keys())if(/01/.test(a.toString(2)))a]

Works properly in the latest versions of Firefox, but probably not in any other browser. Try it out:

<!--                               Try the test suite below!                              --><strong id="bytecount" style="display:inline; font-size:32px; font-family:Helvetica"></strong><strong id="bytediff" style="display:inline; margin-left:10px; font-size:32px; font-family:Helvetica; color:lightgray"></strong><br><br><pre style="margin:0">Code:</pre><textarea id="textbox" style="margin-top:5px; margin-bottom:5px"></textarea><br><pre style="margin:0">Input:</pre><textarea id="inputbox" style="margin-top:5px; margin-bottom:5px">5</textarea><br><button id="testbtn">Test!</button><button id="resetbtn">Reset</button><br><p><strong id="origheader" style="font-family:Helvetica; display:none">Original Code Output:</strong><p><div id="origoutput" style="margin-left:15px"></div><p><strong id="newheader" style="font-family:Helvetica; display:none">New Code Output:</strong><p><div id="newoutput" style="margin-left:15px"></div><script type="text/javascript" id="golfsnippet">var bytecount=document.getElementById("bytecount");var bytediff=document.getElementById("bytediff");var textbox=document.getElementById("textbox");var inputbox=document.getElementById("inputbox");var testbtn=document.getElementById("testbtn");var resetbtn=document.getElementById("resetbtn");var origheader=document.getElementById("origheader");var newheader=document.getElementById("newheader");var origoutput=document.getElementById("origoutput");var newoutput=document.getElementById("newoutput");textbox.style.width=inputbox.style.width=window.innerWidth-50+"px";var _originalCode="x=>[for(a of Array(1<<x).keys())if(/01/.test(a.toString(2)))a]";function getOriginalCode(){if(_originalCode!=null)return _originalCode;var allScripts=document.getElementsByTagName("script");for(var i=0;i<allScripts.length;i++){var script=allScripts[i];if(script.id!="golfsnippet"){originalCode=script.textContent.trim();return originalCode}}}function getNewCode(){return textbox.value.trim()}function getInput(){try{var inputText=inputbox.value.trim();var input=eval("["+inputText+"]");return input}catch(e){return null}}function setTextbox(s){textbox.value=s;onTextboxChange()}function setOutput(output,s){output.innerHTML=s}function addOutput(output,data){output.innerHTML+='<pre style="background-color:'+(data.type=="err"?"lightcoral":"lightgray")+'">'+escape(data.content)+"</pre>"}function getByteCount(s){return(new Blob([s],{encoding:"UTF-8",type:"text/plain;charset=UTF-8"})).size}function onTextboxChange(){var newLength=getByteCount(getNewCode());var oldLength=getByteCount(getOriginalCode());bytecount.innerHTML=newLength+" bytes";var diff=newLength-oldLength;if(diff>0){bytediff.innerHTML="(+"+diff+")";bytediff.style.color="lightcoral"}else if(diff<0){bytediff.innerHTML="("+diff+")";bytediff.style.color="lightgreen"}else{bytediff.innerHTML="("+diff+")";bytediff.style.color="lightgray"}}function onTestBtn(evt){origheader.style.display="inline";newheader.style.display="inline";setOutput(newoutput,"");setOutput(origoutput,"");var input=getInput();if(input===null){addOutput(origoutput,{type:"err",content:"Input is malformed. Using no input."});addOutput(newoutput,{type:"err",content:"Input is malformed. Using no input."});input=[]}doInterpret(getNewCode(),input,function(data){addOutput(newoutput,data)});doInterpret(getOriginalCode(),input,function(data){addOutput(origoutput,data)});evt.stopPropagation();return false}function onResetBtn(evt){setTextbox(getOriginalCode());origheader.style.display="none";newheader.style.display="none";setOutput(origoutput,"");setOutput(newoutput,"")}function escape(s){return s.toString().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}window.alert=function(){};window.prompt=function(){};function doInterpret(code,input,cb){var workerCode=interpret.toString()+";function stdout(s){ self.postMessage( {'type': 'out', 'content': s} ); }"+" function stderr(s){ self.postMessage( {'type': 'err', 'content': s} ); }"+" function kill(){ self.close(); }"+" self.addEventListener('message', function(msg){ interpret(msg.data.code, msg.data.input); });";var interpreter=new Worker(URL.createObjectURL(new Blob([workerCode])));interpreter.addEventListener("message",function(msg){cb(msg.data)});interpreter.postMessage({"code":code,"input":input});setTimeout(function(){interpreter.terminate()},1E4)}setTimeout(function(){getOriginalCode();textbox.addEventListener("input",onTextboxChange);testbtn.addEventListener("click",onTestBtn);resetbtn.addEventListener("click",onResetBtn);setTextbox(getOriginalCode())},100);function interpret(code,input){window={};alert=function(s){stdout(s)};window.alert=alert;console.log=alert;prompt=function(s){if(input.length<1)stderr("not enough input");else{var nextInput=input[0];input=input.slice(1);return nextInput.toString()}};window.prompt=prompt;(function(){try{var evalResult=eval(code);if(typeof evalResult=="function"){var callResult=evalResult.apply(this,input);if(typeof callResult!="undefined")stdout(callResult)}}catch(e){stderr(e.message)}})()};</script>

(Snippet taken from this page)

Suggestions welcome!

JavaScript (ES6), 69 68 67 62 bytes

a=>[...Array(1<<a).keys()].filter(i=>/01/.test(i.toString(2)))

Today I discovered a new shorter way to dynamically fill arrays without the use of fill or map. Doing x=>[...Array(x).keys()] will return an array of range 0 to x. If you want to define your own range/values, use x=>[...Array(x)].map((a,i)=>i), as it's just a few bytes longer.

K5, 19 bytes

This operates along similar principles as Dennis' solution, but with fewer builtins to take advantage of.

{&2<+/'~0=':'+!x#2}

First, generate a series of binary x-tuples (+!x#2), then for each tuple find every point that a digit does not match the previous if we treat the -1st element of the list as 0 for this purpose (~0=':'). Our solutions are where two is less than the sum of each run count. (&2<+/').

Showing each intermediate step is clearer:

  4#2
2 2 2 2

  !4#2
(0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1)

  +!4#2
(0 0 0 0
 0 0 0 1
 0 0 1 0
 0 0 1 1
 0 1 0 0
 0 1 0 1
 0 1 1 0
 0 1 1 1
 1 0 0 0
 1 0 0 1
 1 0 1 0
 1 0 1 1
 1 1 0 0
 1 1 0 1
 1 1 1 0
 1 1 1 1)

  ~0=':'+!4#2
(0 0 0 0
 0 0 0 1
 0 0 1 1
 0 0 1 0
 0 1 1 0
 0 1 1 1
 0 1 0 1
 0 1 0 0
 1 1 0 0
 1 1 0 1
 1 1 1 1
 1 1 1 0
 1 0 1 0
 1 0 1 1
 1 0 0 1
 1 0 0 0)

  +/'~0=':'+!4#2
0 1 2 1 2 3 2 1 2 3 4 3 2 3 2 1

  2<+/'~0=':'+!4#2
0 0 0 0 0 1 0 0 0 1 1 1 0 1 0 0

  &2<+/'~0=':'+!4#2
5 9 10 11 13

And all together:

  {&2<+/'~0=':'+!x#2}'3 4 5 
(,5
 5 9 10 11 13
 5 9 10 11 13 17 18 19 20 21 22 23 25 26 27 29)

Julia, 43 41 bytes

n->filter(i->ismatch(r"01",bin(i)),1:2^n)

This creates an unnamed function that accepts an integer and returns an array. It uses histocrats's regex trick (used in Doorknob's answer), where 01 will only match if there's a preceding 1.

Ungolfed:

function f(n::Int)
    # Take the integers from 1 to 2^n and filter them down to
    # only those such that the binary representation of the integer
    # matches the regex /01/.
    filter(i -> ismatch(r"01", bin(i)), 1:2^n)
end

APL, 34 27 bytes

{0~⍨{⍵×2<+/2≢/⍵⊤⍨⍵/2}¨⍳2*⍵}

This creates an unnamed monadic function that accepts an integer on the right and returns an array.

Explanation:

                     }¨⍳2*⍵}  ⍝ For each integer from 1 to 2^input...
              ⍵⊤⍨⍵/2         ⍝ Get the binary representation as a vector
           2≢/                ⍝ Pairwise non-match, yielding a boolean vector
       2<+/                   ⍝ Check whether the number of trues is >2
     ⍵×                       ⍝ Yield the integer if so, otherwise 0
{0~⍨{                         ⍝ Remove the zeros from the resulting array

Saved 7 bytes thanks to Dennis!

Perl 5, 55 53 49 47 41 bytes

sprintf("%b",$_)=~/01/&&say for 0..2**<>

54 52 48 46 40 bytes, plus one for the -E flag instead of -e.


Thanks to xnor for the hint about using /01/ instead of /10+1/, which saved two bytes.

Thanks to Dennis for the advice to use <> instead of $ARGV[0], which saved six bytes.

C++, 197 188 141 bytes

Note: this was written and tested using MSVC++ 2013. It appears that #includeing <iostream> includes all of the necessary C headers to make this work. It also appears that the code is no longer truly C++, but compiling using C++ allows that header trick which reduces the code size compared to including a bunch more C headers.

Using printf instead of cout also saves a couple bytes.

Golfed:

#include<iostream>
int main(int a,char**b){char c[34];for(long i=5;i<1L<<atol(b[1]);++i){_ltoa(i,c,2);if(strstr(c,"01"))printf("%ld\n",i);}}

Ungolfed:

#include <iostream>
int main(int a, char **b) {
  char c[34];
  for (long i = 5; i < 1L << atol(b[1]); ++i) {
    _ltoa(i, c, 2);
    if (strstr(c, "01"))
      printf("%ld\n", i);
  }
}

Julia, 40 bytes

n->filter(i->count_ones(i$i>>1)>2,1:2^n)

This uses a somewhat different approach to the other Julia solution - rather than doing a string search for "01" in the bit string, it uses some mathematics to determine whether the number satisfies the condition.

i$i>>1 will have ones only in the places where the digit changes from zero to one, or one to zero. As such, there must be at least three ones for i to switch back and forth between zero and one enough times. count_ones finds the number of ones, and then filter removes the ones that don't have enough ones.

CJam, 14

2qi#{2b2,#)},p

3 bytes shorter thanks to Dennis. Try it online

Python 2.7, 89 bytes

print[i for i in range(1,2**input())if[n[:1]for n in bin(i)[2:].split("0")].count("1")-1]

I think this could be golfed a bit.

Pyth, 12 bytes

f<2r.BT8U^2Q

Try it online.

Idea

The binary representation of any positive number always begins with a run of 1s, possibly followed by other, alternating runs of 0s and 1s. If there are at least three separate runs, two of them are guaranteed to be runs of 1s.

Code

              (implicit) Store the evaluated input in Q.
         ^2Q  Calculate 2**Q.
f       U     Filter; for each T in [0, ..., 2**Q-1]:
    .BT         Compute T's binary representation.
   r   8        Perform run-length encoding.
                This returns a list of character/run-length pairs.
 <2             Discard the trailing two pairs.
                This returns a non-empty array if there are more than 2 runs.
              Keep T if the array was truthy (non-empty).

Pip, 13 + 1 = 14 bytes

Takes input from the command line and uses the -s flag for spaces between output numbers.

01NTB_FI,2**a

Pretty straightforward: build range(2**a) and filter on lambda _: "01" in toBinary(_). I was pretty happy about thinking up the 01 idea independently. No quotes are needed around 01 because it scans as a numeric literal (numbers and strings are the same type in Pip).

JavaScript (ES6) 76

f=n=>Array(1<<n).fill().map((_,x)=>/01/.test(x.toString(2))?x+',':'').join``

//TEST
for(i=1;i<16;i++)O.innerHTML+=i+' -> '+f(i)+'\n'
<pre id=O></pre>

Pyth, 20 17 16 bytes

f:.BT"10+1"ZU^2Q

Live demo.

Python, 48

lambda n:[i for i in range(2**n)if'01'in bin(i)]

I had been vastly overthinking this. We just need to check if the binary expansion contains '01'.

For there to be two runs of ones, the one on the right must be preceded by a 0. If there's only one run, there won't be any leading 0's, so that won't happen.


Old answer:

lambda n:[i for i in range(2**n)if len(set(bin(i).split('0')))>2]

The Python binary representation works very nicely here. A binary number is written like bin(9)=='0b10110'. Splitting at '0' results in a list of

The first two categories always exist, but the last one only exists if there is a run one 1's that doesn't contain the leading '1', and so only if there's more than one run of 1's. So, it suffices to check if the list contains more than 2 distinct elements.

Python 3.5 saves 2 chars by unpacking {*_} in place of set(_).

R, 55 47 bytes

(with some help from @Alex.A)

cat(grep("10+1",R.utils::intToBin(1:2^scan())))

R doesn't have a built in function to display converted numbers in a convenient way, so I'm using R.utils::intToBin for this, while all the rest is pretty much just report the location of the matched regex expression and print to STDOUT while separated by a space.

Ruby, 44 40 38 chars

crossed out 44 is still regular 44 ;(

->n{(0..2**n).select{|x|/01/=~'%b'%x}}

An anonymous function (proc, actually) that takes an integer and returns an array.

Uses the regex /10+1/: a 1, at least one 0, and then another 1. @histocrat points out that if 01 is anywhere in the string, there must be a 1 somewhere before it.

Matlab, 79 68 64 59

The idea is interpreting the binary number as array of zeros and ones, and then calculating the absolute difference between each pair of neighbours. If we have two or more times a difference of 1, then we obviously have a run of two or more ones. Note that this only works if we represent the binary number without leading zeros.

@(n)find(arrayfun(@(k)sum(~~diff(dec2bin(k)+0))>1,1:2^n-1))

Old versions:

k=1:2^input('')-1;k(arrayfun(@(k)sum(~~diff(dec2bin(k)+0))>1,k))

for k=1:2^input('')-1;if sum(~~diff(dec2bin(k)+0))>1;disp(k);end;end

for k=1:2^input('')-1;if sum(~~conv(dec2bin(k)+0,[-1,1],'v'))>1;disp(k);end;end