[Question]
  [
The sequence contains the decimal representation of the binary numbers of the form: `10101...`, where the n-th term has n bits.
The sequence is probably easiest to explain by just showing the relationships between the binary and decimal representations of the numbers:
```
0       ->  0
1       ->  1
10      ->  2
101     ->  5
1010    ->  10
10101   ->  21
101010  ->  42
```
### Challenge:
Take an input integer `n`, and return the first n numbers in the sequence. You may choose to have the sequence 0-indexed or 1-indexed.
### Test cases:
```
n = 1   <- 1-indexed
0
n = 18
0, 1, 2, 5, 10, 21, 42, 85, 170, 341, 682, 1365, 2730, 5461, 10922, 21845, 43690, 87381
```
**Explanations are encouraged, as always.**
This is [OEIS A000975](https://oeis.org/A000975).
  
[Answer]
# [Python 2](https://docs.python.org/2/), 36 bytes
```
lambda n:[2**i*2/3for i in range(n)]
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHPKtpISytTy0jfOC2/SCFTITNPoSgxLz1VI08z9n9BUWZeiUKahqGF5n8A "Python 2 – Try It Online") Explanation: The binary representation of \$\frac{2}3\$ is `0.101010101...` so it simply remains to multiply it by an appropriate power of 2 and take the integer portion.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
2 bytes saved using [Neil's 2/3 trick](https://codegolf.stackexchange.com/a/153797/47066) 
```
Lo3÷
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fJ9/48Pb//w0tAA "05AB1E – Try It Online")
**Explanation**
```
L      # push range [1 ... input]
 o     # raise 2 to the power of each
  3÷   # integer division of each by 3
```
---
# [05AB1E](https://github.com/Adriandmen/05AB1E), 6 bytes
```
TRI∍ηC
```
[Try it online!](https://tio.run/##MzBNTDJM/f8/JMjzUUfvue3O//8bWgAA "05AB1E – Try It Online")
**Explanation**
```
T        # push 10
 R       # reverse it
  I∍     # extend to the lenght of the input
    η    # compute prefixes
     C   # convert each from base-2 to base-10
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~...~~ 4 bytes
Thanks *[miles](https://codegolf.stackexchange.com/users/6710)* for -1 byte!
```
ḶḂḄƤ
```
[Try it online!](https://tio.run/##y0rNyan8///hjm0PdzQ93NFybMn///8NDQA "Jelly – Try It Online")
Explanation:
```
Ḷ     **Ḷ**owered range, or Un**Ḷ**ength. Get [0, 1, 2, 3, ..., n-1]
 Ḃ    **Ḃ**it. Get the last bit of each number. [0, 1, 0, 1, ...]
   Ƥ  for each **Ƥ**refixes [0], [0, 1], [0, 1, 0], [0, 1, 0, 1], ...
  Ḅ   convert it from **Ḅ**inary to integer.
```
---
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
Jonathan Allan's version.
```
Ḷ€ḂḄ
```
[Try it online!](https://tio.run/##y0rNyan8///hjm2PmtY83NH0cEfL////zQE "Jelly – Try It Online")
```
Ḷ     **Ḷ**owered range, or Un**Ḷ**ength.
 €    Apply for **€**each. Automatically convert the number **n**
      to the range *[1,2,..,n]*. Get *[[0],[0,1],[0,1,2],..]*.
  Ḃ   **Ḃ**it. Get the last bit from each number.
      Current value: *[[0],[0,1],[0,1,0],..]*
   Ḅ  Convert each list from **Ḅ**inary to integer.
```
---
A version based on Neil's 2/3 trick gives 5 bytes, see revision history.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 5 bytes
```
:WI/k
```
Based on [Neil's answer](https://codegolf.stackexchange.com/a/153797/36398).
### Explanation
```
:       % Implicit input, n. Push range [1 2 ... n]
W       % 2 raised to that, element-wise. Gives [2 4 ...2^n] 
I       % Push 3
/       % Divide, element-wise
k       % Round down, element-wise. Implicit display
```
[Try it online!](https://tio.run/##y00syfn/3yrcUz/7/39DCwA "MATL – Try It Online")
---
# [MATL](https://github.com/lmendo/MATL), 9 bytes
```
:q"@:oXBs
```
[Try it online!](https://tio.run/##y00syfn/36pQycEqP8Kp@P9/QwsA "MATL – Try It Online")
### Explanation
```
:       % Implicit input n. Range [1 2 ... n]
q       % Subtract 1, element-wise: gives [0 1 ... n-1]
"       % For each k in [0 1 ... n-1]
  @     %   Push k
  :     %   Range [1 2 ... k]
  o     %   Modulo 2, element-wise: gives [1 0 1 ...]
  XB    %   Convert from binary to decimal
  s     %   Sum. This is needed for k=0, to transform the empty array into 0
        % Implicit end. Implicit display
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~45~~ ~~37~~ 36 bytes
-3 bytes thanks to user202729  
-1 byte thanks to mathmandan 
```
s=0
exec"print s;s+=s+~s%2;"*input()
```
[Try it online!](https://tio.run/##K6gsycjPM/r/v9jWgCu1IjVZqaAoM69Eodi6WNu2WLuuWNXIWkkrM6@gtERD8/9/QwsA "Python 2 – Try It Online")
[Answer]
# Python 3, ~~68~~ ~~61~~ ~~54~~ ~~48~~ 43 bytes
```
c=lambda x,r=0:x and[r]+c(x-1,2*r+~r%2)or[]  
```
Thanks to [user202729](https://codegolf.stackexchange.com/users/69850/user202729) for helping save 19 bytes and [ovs](https://codegolf.stackexchange.com/users/64121/ovs) for helping save 6 bytes.
[Try It Online](https://tio.run/##K6gsycjPM9ZNBtP//yfb5iTmJqUkKlToFNkaWFUoJOalRBfFaidrVOga6hhpFWnXFakaaeYXRcf@LyjKzCvRSNYwtNDU5IJzDDQ1/wMA)
[Answer]
## [Husk](https://github.com/barbuz/Husk), 7 bytes
```
mḋḣ↑Θİ¬
```
[Try it online!](https://tio.run/##ARoA5f9odXNr//9t4biL4bij4oaRzpjEsMKs////NQ "Husk – Try It Online")
1-based, so input **n** gives the first **n** results.
### Explanation
```
     İ¬   The infinite list [1, 0, 1, 0, 1, ...]
    Θ     Prepend a zero.
   ↑      Take the first n elements.
  ḣ       Get the prefixes of that list.
mḋ        Interpret each prefix as base 2.
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 11 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte charater set")
Assumes `⎕IO` (**I**ndex **O**rigin) to be `0`, which is default on many systems. Anonymous tacit prefix function. 1-indexed.
```
(2⊥⍴∘1 0)¨⍳
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OApIbRo66lj3q3POqYYahgoHloxaPezf//pykYcgGxBQA "APL (Dyalog Unicode) – Try It Online")
`⍳` **ɩ**ndices 0…n−1
`(`…`)¨` apply the following tacit function to each
 `⍴∘1 0` cyclically reshape the list `[1,0]` to that length
 `2⊥` convert from base-2 (binary) to normal number
[Answer]
# [Perl `v5.10`](https://www.perl.org/) `-n`, 24+1 bytes
-3 bytes thanks to [Nahuel Fouilleul](https://codegolf.stackexchange.com/users/70745/nahuel-fouilleul)!
```
say$v=$v*2|$|--while$_--
```
[Try it online!](https://tio.run/##K0gtyjH9X1qcqlBmqmdoYP2/OLFSpcxWpUzLqEalRle3PCMzJ1UlXlf3/39Di3/5BSWZ@XnF/3XzAA "Perl 5 – Try It Online")
Same logic as my Ruby version, but shorter because perl is more concise. For some odd reason, `print` wouldn't do a seperator (dammit!), so I had to use `say` from `v5.10;` in order for this to run, I'm not sure how to score this, so I'm leaving it out for now?...
## Explanation
```
say    # Like shouting, but milder.
  $v = $v*2 | $|-- # Next element is this element times 2 bitwise-OR
                   # with alternating 0 1 0 1..., so 0b0, 0b1, 0b10, 0b101...
                   # $. is OUTPUT_AUTOFLUSH, which is initially 0 and
                   #   setting all non-zero values seem to be treated as 1
  while $_-- # do for [input] times
```
[Answer]
# [Haskell](https://www.haskell.org/), 33 bytes
```
l=1:0:l
($scanl((+).(2*))0l).take
```
[Try it online!](https://tio.run/##VYxNC4JAFEX3/oqbtNAScT7USZhN2yIXtYsgyRHFySIN6tfbcxHUW91zLvfVRd8aa8fRapZFmXUq7c37S9FZz1v6occXvh9ZPxyK1owvnPv69rTl2pzxhsb9OeyHx7bDHE2Fl9ZvDLXp4OYbF8b2Bu4uPyDfzFw4zrVoOhqVNwd0Fdjvu2N0@mr17wOwADxATIGAE0lCNXFKQkgyiSLFREKSp4JsLBM2DVacTxslqZEiWVGlUqHYafwA "Haskell – Try It Online")
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 7 bytes
```
⌊3÷⍨2*⍳
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24RHPV3Gh7c/6l1hpPWodzNQTMGQC4gtAA "APL (Dyalog Unicode) – Try It Online")
---
# [APL (Dyalog)](https://www.dyalog.com/), 11 bytes
```
(2⊥2|⍳)¨1+⍳
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OApIbRo66lRjWPejdrHlphqA2k//9PUzDkAmILAA "APL (Dyalog Unicode) – Try It Online")
Uses `⎕IO←0`.
[Answer]
# [C](https://en.wikipedia.org/wiki/C_(programming_language)), ~~81 55~~ 59 bytes
1 indexed.
```
i,j;f(c){for(i=j=0;i<c;)printf("%d ",i++&1?j+=j+1:(j+=j));}
```
Full program, less golfed:
```
i;j;main(c,v)char**v;{c=atoi(*++v);for(;i<c;i++)printf("%d ",i&1?j+=j+1:(j+=j));}
```
[Try it online!](https://tio.run/##FctBDsIgEEDRtZyCNNEMDKayM1LiznuQUXRILIYQNk3PTuvqb96n85uodzbJRSC1xFyAffIXxxM59Ss81wjD8SkHw4gne0/oE9ob/KuUW/s4ykfO9VXEbuU38AxkmqJPKFo3t4hDhFAzg0Zs@yHW3u11Aw "C (gcc) – Try It Online")
EDIT 2: I was under the assumption that functions didn't need to be reusable now that I think of it, it makes perfect sense that they would have to be reusable :P
EDIT: I was under the misconception that I had to include the entire program in the answer, turns out I only needed the function that does it. That's nice.
I'm decently sure I can shave off a few bytes here and there. I've already employed a few tricks. A large chunk of the program is dedicated to getting the argument and turning it into an int. This is my first code golf. If I'm doing anything wrong tell me :P
[Answer]
# [Haskell](https://www.haskell.org/), 47 40 53 49 44 40 34 bytes
-4 bytes thanks to user202729  
-6 bytes thanks to Laikoni
```
(`take`l)
l=0:[2*a+1-a`mod`2|a<-l]
```
[Try it online!](https://tio.run/##HYo7C8IwFEb3/opbcGgtkbaTSDs4uLl1VCGXNn3QvEiuiuBvN4ae5Tt8nBn9KqQMi7LGEXQfT0IdLvq1OKOV0JSM7T1knHAVXOaJbMvTrd5jUTHkygy8/mLD5CMoXDS0MJgEIugmDw2DSdA56vbZJ3Xkrhp24GfzjjNC5gQO0bY@TaHMQ6iOv36UOPnAemv/ "Haskell – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 26 bytes
```
->n{(1..n).map{|i|2**i/3}}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vWsNQTy9PUy83saC6JrPGSEsrU9@4tvZ/gUKaXnJiTo6GoYXmfwA "Ruby – Try It Online")
Beats all the older ruby answers.
## Explanation
`1/3` in binary looks like `0.01010101...`, so If you multiply it by powers of two, you get:
```
n| 2^n/3
-+---------
1|0.1010101...
2|01.010101...
3|010.10101...
4|0101.0101...
5|01010.101...
6|010101.01...
```
But Ruby floors the numbers on int division, giving me the sequence I need.
[Answer]
# [J](http://jsoftware.com/), 9 bytes
```
[:#.\2|i.
```
## How it works?
`i.` - list 0..n-1
`2|` - the list items mod 2
`\` - all prefixes
`#.` - to decimal
`[:` - caps the fork (as I have even number (4) of verbs)
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/o62U9WKMajL1/mtyKXClJmfkK6QpGFr8BwA "J – Try It Online")
[Answer]
## [Retina](https://github.com/m-ender/retina/wiki/The-Language), 28 bytes
```
)K`0
"$+"+¶<`.+
$.(*__2*$-1*
```
[Try it online!](https://tio.run/##K0otycxLNPz/X9M7wYBLSUVbSfvQNpsEPW0uFT0Nrfh4Iy0VXUOt//8NzQE "Retina – Try It Online")
0-based, so input **n** gives the first **n+1** results.
### Explanation
Uses the recursion from OEIS:
```
a(n) = a(n-1) + 2*a(n-2) + 1
```
Let's go through the program:
```
)K`0
```
This is a constant stage: it discards the input and sets the working string to `0`, the initial value of the sequence. The `)` wraps this stage in a group. That group itself does nothing, but almost every stage (including group stages) records its result in a log, and we'll need two copies of the `0` on that log for the program to work.
```
"$+"+¶<`.+
$.(*__2*$-1*
```
There's a bunch of configuration here: `"$+"+` wraps the stage in a loop. The `"$+"` is treated as a substitution, and `$+` refers to the program's input, i.e. **n**. This means that the loop is run **n** times.
Then `¶<` wraps each iteration in an output stage, which prints the stage's *input* with a trailing linefeed (so the first iteration prints the zero, the second iteration prints the first iteration's result and so on).
The stage itself replaces the entire working string with the substitution on the last line. That one makes use of an implicit closing parenthesis and implicit arguments for the repetition operator `*`, so it's actually short for:
```
$.($&*__2*$-1*_)
```
The stuff inside the parentheses can be broken up into three parts:
* `$&*_`: gives a string of **a(n-1)** `_`s.
* `_`: gives a single `_`.
* `2*$-1*_`: gives a string of **2\*a(n-1)** `_`. The `$-1` refers to the penultimate result in the result log, i.e. the loop iteration before the last. That's why we needed to copies of the zero on the log to begin with, otherwise this would refer to the program's input on the first iteration.
Then `$.(…)` measures the length of the resulting string. In other words, we've computed `a(n) = a(n-1) + 1 + 2*a(n-2)` by going through unary (not really though: `$.(…)` is lazy and doesn't actually evaluate its content if it can determine the resulting length directly through arithmetic, so this is even quite efficient).
The result of the final loop iteration (the **n+1**th element of the sequence) is printed due to Retina's implicit output at the end of the program.
[Answer]
# Java 8, ~~115~~ ~~81~~ ~~80~~ 52 bytes
```
n->{for(int i=2;n-->0;i*=2)System.out.println(i/3);}
```
Port of [*@Neil*'s Python 2 answer](https://codegolf.stackexchange.com/a/153797/52210).  
1-indexed and outputted directly, each value on a separated line.
**Explanation:**
[Try it online.](https://tio.run/##bY7BDoIwDIbvPkWPm8lQ8WKywBvIhaPxMMcgw9ERNkgM4dnnBI4m7aH9//79WjEJZnuFbfUO0gjn4C40zgcAjV4NtZAKit8IMFldgSTGYgNIedwtsWM5L7yWUABCBgFZPtd2IPEedJZyZCw/c33MUlp@nFddYkef9EPUDRJ9ulK@BL4l9ePLxKQ9cH3YRRxS@mhvHk9BNxRMJLmsCAB/Qndldd120iV8AQ)
```
n->{                           // Method with integer parameter and no return-type
  for(int i=2;                 //  Start integer `i` at 2
      n-->0;                   //  Loop `n` times:
      i*=2)                    //    Multiply `i` by 2 after every iteration
    System.out.println(i/3);}  //   Print `i` integer-divided by 3 and a new-line
```
---
**Old 80 bytes answer:**
```
n->{String t="",r=t;for(Long i=0L;i<n;)r+=i.parseLong(t+=i++%2,2)+" ";return r;}
```
1-indexed input and space-delimited `String` output
**Explanation:**
[Try it online.](https://tio.run/##dY/BCsIwDIbvPkUYCC3ToZ6EWp9g7uJRPNRapTrTkWaCyJ59drqrkBCSP@H7czNPMw@Nw9v53tvaxAg74/E9AfDIji7GOqiGFmDP5PEKVtQhFZQqTbuUKSIb9hYqQNDQ43z7HpdZZ9mMNKtLIFEOd14vSuU3qCTl2heNoegGQXBq83y6mq1knkGmyHFLCKS6Xv0oTXuqE2WEPYM/wyOZFT/W4WjkaPQV2T2K0HLRJIVrFFhYsZRfy//1tRx/6voP)
```
n->{                             // Method with integer parameter and String return-type
  String t="",r=t;               //  Temp and result-Strings, both starting empty
  for(Long i=0L;i<n;)            //  Loop from 0 to `n` (exclusive)
    r+=                          //   Append the result-String with:
       i.parseLong(        ,2);  //    Binary to integer conversion
                   t+=           //     append the temp-String with:
                      i  %2      //      current index `i` modulo-2
                       ++        //      and increase `i` by one afterwards
       +" ";                     //    + a space
  return r;}                     //  Return the result-String
```
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 36 bytes
```
{([()]{}<((({}<>)<>){}([{}]()))>)}<>
```
[Try it online!](https://tio.run/##SypKzMzTTctJzP7/v1ojWkMztrrWRkNDA0jaaQJRda1GdHVtrIampqadJlDs/38TAA "Brain-Flak – Try It Online")
## Explanation:
The next number in the sequence is obtained by `n*2+1` or `n*2+0`.
```
{([()]{}< Loop input times
  (
   (({}<>)<>){} Copy n to other stack; n*2
   ([{}]())  i = 1-i
  ) push n*2 + i
>)} End loop
<> Output other stack
```
[Answer]
# [Ruby](http://www.ruby-lang.org) ~~42 41 43 41 37 35 31 33~~ 30 bytes
-2 bytes thanks to Unihedron
-3 bytes thanks to G B
```
->x{a=0;x.times{a-=~a+p(a)%2}}
```
[Try it online!](https://tio.run/##KypNqvyfZhvzX9euojrR1sC6Qq8kMze1uDpR17YuUbtAI1FT1ai29n9atKFF7H8A)
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 22 + 3 (-v flag) bytes
```
0:nao::1+2%++$1-:?!;$!
```
[Try it online!](https://tio.run/##S8sszvj/38AqLzHfyspQ20hVW1vFUNfKXtFaRfH///@6ZeYA "><> – Try It Online")
### Explanation
The stack gets initialized with the loop counter.
```
0:nao                  : Push 0 to the stack, duplicate and print with a new line.
                         [7] -> [7, 0]
     ::1+              : Duplicate the stack top twice more then add 1 to it.
                         [7, 0] -> [7, 0, 0, 1]
         2%++          : Mod the stack top by 2 then add all values on the stack bar the loop counter.
                         [7, 0, 0, 1] -> [7, 1]
             $1-:?!;$! : Swap the loop counter to the top, minus 1 from it and check if zero, if zero stop the program else continue.
```
[Answer]
# [Perl 6](https://perl6.org), ~~35 30 27 25~~ 20 bytes
```
{[\~](0,+!*...*)[^$_]».&{:2(~$_)}}
```
[Try it (35)](https://tio.run/##K0gtyjH7X1qcqlBmppdszaVXnFipkJZfpJCSr5CeWZaap6BhaKH5vzo6pi5Ww0BHW1FLT09PSzM6TiU@9tBuPbVqKyONOpV4zdra//8B "Perl 6 – Try It Online")
```
{(0,{$_*2+|($+^=1)}…*)[^$_]}
```
[Try it (30)](https://tio.run/##K0gtyjH7X1qcqlBmppdszaVXnFipkJZfpJCSr5CeWZaap6BhaKH5v1rDQKdaJV7LSLtGQ0U7ztZQs/ZRwzItzeg4lfjY2v//AQ "Perl 6 – Try It Online")
```
{(⅓X*(2,4,8…2**$_))».Int}
```
[Try it (30)](https://tio.run/##K0gtyjH7X1qcqlBmppdszaVXnFipkJZfpJCSr5CeWZaap6BhaKH5v1rjUevkCC0NIx0THYtHDcuMtLRU4jU1D@3W88wrqf3/HwA "Perl 6 – Try It Online")
```
{(⅔,* *2…*)[^$_]».Int}
```
[Try it (27)](https://tio.run/##K0gtyjH7X1qcqlBmppdszaVXnFipkJZfpJCSr5CeWZaap6BhaKH5v1rjUesUHS0FLaNHDcu0NKPjVOJjD@3W88wrqf3/HwA "Perl 6 – Try It Online")
```
{((2 X**1..$_)X/3)».Int}
```
[Try it (25)](https://tio.run/##K0gtyjH7X1qcqlBmppdszaVXnFipkJZfpJCSr5CeWZaap6BhaKH5v1pDw0ghQkvLUE9PJV4zQt9Y89BuPc@8ktr//wE "Perl 6 – Try It Online")
```
{(2 X**1..$_)Xdiv 3}
```
[Try it (20)](https://tio.run/##K0gtyjH7X1qcqlBmppdszaVXnFipkJZfpJCSr5CeWZaap6BhaKH5v1rDSCFCS8tQT08lXjMiJbNMwbj2/38A "Perl 6 – Try It Online")
## Expanded:
```
{
 (
  2                  # 2
    X**              # cross to the power of
       1..$_         # Range from 1 to the input (inclusive)
            )
             Xdiv    # cross using integer divide
                  3  # by 3
}
```
[Answer]
# [Python 2](https://docs.python.org/2/), 33 bytes
```
s=2
exec"print s/3;s*=2;"*input()
```
[Try it online!](https://tio.run/##K6gsycjPM/r/v9jWiCu1IjVZqaAoM69EoVjf2LpYy9bIWkkrM6@gtERD8/9/MwA "Python 2 – Try It Online")
---
# [Python 2](https://docs.python.org/2/), 34 bytes
```
f=lambda n:n*[f]and[2**n/3]+f(n-1)
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P802JzE3KSVRIc8qTys6LTYxLyXaSEsrT984VjtNI0/XUPN/QVFmXolCmkZmXkFpiYam5n8zAA "Python 2 – Try It Online")
Returns in reverse order.
[Answer]
# C, ~~47~~ 46 bytes
```
a;f(n){for(a=0;n--;a+=a-~a%2)printf("%d ",a);}
```
The accumulator `a` begins with zero. At each step, we double it (`a+=a`) and add one if the previous least-significant bit was zero (`!(a%2)`, or equivalently, `-(~a)%2`).
## Test program
```
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
    while (*++argv) {
        f(atoi(*argv));
        puts("");
    }
}
```
## Results
```
$ ./153783 1 2 3 4 5 6
0 
0 1 
0 1 2 
0 1 2 5 
0 1 2 5 10 
0 1 2 5 10 21 
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt/), ~~10~~ ~~9~~ ~~7~~ 6 bytes
All derived independently from other solutions.
1-indexed.
```
õ!²mz3
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.5&code=9SGybXoz&input=OA==)
---
## Explanation
```
õ        :[1,input]
 !²      :Raise 2 to the power of each
   m     :Map
    z3   :Floor divide by 3
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.5&code=9SGybXoz&input=OA==)
---
## 7 byte version
```
õ_ou ì2
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.5&code=9V9vdSDsMg==&input=OA==)
```
õ            :[1,input]
 _           :Pass each through a function
   o         :[0,current element)
    u        :Modulo 2 on above
      ì2     :Convert above from base-2 array to base-10
```
---
## 9 byte version
```
õ_îA¤w)n2
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.5&code=9V/uQaR3KW4y&input=OAotUQ==)
```
õ            :[1,input]
 _           :Pass each through a function
   A         :10
    ¤        :Convert to binary
     w       :Reverse
  î          :Repeat the above until it's length equals the current element
      )      :Close nested methods
       n2    :Convert from binary to base-10
```
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2), 4 [bytes](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)
```
RO3÷
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728JKM0Ly_faMGCpaUlaboWS4P8jQ9vX1KclFwMFVmwyNACwgIA)
Port of Neil's Python answer.
#### Explanation
```
RO3÷  # Implicit input       ->  5
R     # Push [1..input]      ->  [1,2,3,4,5]
 O    # Two power of each    ->  [2,4,8,16,32]
  3÷  # Integer divide by 3  ->  [0,1,2,5,10]
      # Implicit output
```
[Answer]
# [Haskell](https://www.haskell.org/), 52 bytes
```
(`take`map a[0..])
a 0=0
a 1=1
a n=a(n-1)+2*a(n-2)+1
```
[Try it online!](https://tio.run/##FcaxDkAwEADQ3VfcYGhJpdfJcl@CxEVaRDUN/X6H5eVtfB8@Rgk0ipoLH34@OQMPtusmXTFYsp9I@JmIVTKoW9f8cbpFOXlPQJCvPRWoIQD28iwh8nqLWXJ@AQ "Haskell – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), 7 bytes
```
:&+oRXB
```
[Try it online!](https://tio.run/##y00syfn/30pNOz8owun/fwsA "MATL – Try It Online")
**Explanation:**
```
         % Implicitly grab input, n
:        % Range: 1 2 ... n
 &+      % Add the range to itself, transposed
         % 2 3 4 5 ...
         % 3 4 5 6 ...
         % 4 5 6 7 ...
         % 5 6 7 8 ...
   o     % Parity (or modulus 2)
         % 0 1 0 1 ...
         % 1 0 1 0 ...
         % 0 1 0 1 ...
         % 1 0 1 0 ...
    R    % Upper triangular matrix:
         % 0 1 0 1
         % 0 0 1 0
         % 0 0 0 1
         % 0 0 0 0
    XB   % Convert rows to decimal:
         % [5, 2, 1, 0]
         % Implicitly output
```
The output would be `0, 1, 2, 5 ...` if `P` was added to the end (`flip`), making it 8 bytes.
[Answer]
# [Ruby](https://www.ruby-lang.org/) `-n`, ~~32~~ 30+1 bytes
Since we have exactly 1 line of input, `$.` is godly convenient!
EDIT: I'm amazed that I managed to outgolf myself, but it seems using `-n` which counts as 1 (by rule 2 in [default special conditions](https://codegolf.meta.stackexchange.com/a/7539/21830), since Ruby can be run with `ruby -e 'full program'` (thus `-n` is 1) all instances of `gets` which is only used once can be golfed down 1 char this way; I believe this is a milestone for ruby, please speak up if you disagree with this train of thought before I repeatedly reuse it in the future)
```
v=0
?1.upto($_){p v=v*2|$.^=1}
```
[Try it online!](https://tio.run/##KypNqvz/v8zWgMveUK@0oCRfQyVes7pAocy2TMuoRkUvztaw9v9/Q4t/@QUlmfl5xf918wA "Ruby – Try It Online")
## Explanation
```
# while gets(); -- assumed by -n
v=0            # First element of the sequence
?1.upto($_){   # Do from "1" to "$LAST_READ_LINE" aka: Repeat [input] times
  p            # print expression
  v=v*2|$.^=1  # Next element is current element times two
               # bitwise-or 0 or 1 alternating
               # $. = lines of input read so far = 1 (initially)
}
# end           -- assumed by -n
```
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html) `a=0`, 31 bytes
```
{for(;$1--;a=a*2+1-a%2)print a}
```
[Try it online!](https://tio.run/##SyzP/v@/Oi2/SMNaxVBX1zrRNlHLSNtQN1HVSLOgKDOvRCGx9v9/Q4v/ibYGAA "AWK – Try It Online")
Uses the formula shamelessly stolen from [this other Ruby answer.](https://codegolf.stackexchange.com/a/153788/21830)
While not having `a=0` would work (awk treats "empty" as 0), the first element of 0 won't get printed and instead be an `empty` line, which while I would argue is a valid output probably won't pass, so there's `a=0` which can be inserted as command line argument.
[Answer]
# C, 52 bytes
```
i,k;f(n){for(i=k=0;i<n;k=++i%2+2*k)printf("%d ",k);}
```
1-indexed
[Try it online!](https://tio.run/##DcdBCoAgEADAu68QQdjNgvIUbD4mDGNZspBu4tutuU2czhh751EoQcaa7gIcJMzEWyYJzrH1zg@CT@H8JjD20GYUpNb/62vnDKiq0r8Ey4qkWv8A)
]