[Question]
  [
Computers like binary. Humans like base 10. Assuming users are humans, why not find the best of both worlds?
Your task is to find the first `n` terms in the sequence [A008559](https://oeis.org/A008559) where each term is the binary representation of the previous number interpreted as a base 10 number.
## Input
An integer greater than 0. Note that the first value of A008559 is 2.
## Output
Just to make it a little more readable, the output should be the number of digits in the Nth term of A008559, which is [A242347](https://oeis.org/A242347).
Invalid inputs can output whatever, standard [sequence](/questions/tagged/sequence "show questions tagged 'sequence'") rules apply.
## Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so shortest bytecount wins, no standard loopholes etc...
## Test Cases
```
2 -> [1,2]
5 -> [1,2,4,10,31]
10 -> [1,2,4,10,31,100,330,1093,3628,12049]
20 -> [1,2,4,10,31,100,330,1093,3628,12049,40023,132951,441651,1467130,4873698,16190071,53782249,178660761,593498199,1971558339]
```
  
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~38~~ ~~33~~ 25 bytes
```
a=2;loop{p /$/=~a="%b"%a}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsGCpaUlaboWOxNtjaxz8vMLqgsU9FX0besSbZVUk5RUE2sh8lBlMOUA)
Outputs the sequence indefinitely starting from 2.
Thanks for a whopping -13 bytes from a collective effort by south and Dingus.
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~9~~ 9 bytes
```
¡o§,ḋLd;2
```
[Try it online!](https://tio.run/##yygtzv7/qG2iocGjpsb/hxbmH1qu83BHt0@KtdH//wA "Husk – Try It Online")
Outputs the infinite sequence.
---
The previous version (also 9 bytes when outputting the infinite sequence) was
`moLd¡odḋ2`, but I've cleaned this up at the [request of lyxal](https://codegolf.stackexchange.com/questions/253857/length-of-binary-as-base-10-oeis-a242347/253861#comment563846_253861), who considered it too odd due to the moLd in it.
```
         2 # starting with 2
     ¡     # construct an infinite sequence
      o    # by repeatedly applying 2 functions:
        ḋ  #   convert to binary digits
       d   #   convert from base-10 digits
 m         # now map over this infinite list
  o        # using 2 functions:
   L       #   length of
    d      #   base-10 digits
```
[Answer]
# [Fig](https://github.com/Seggan/Fig), \$8\log\_{256}(96)\approx\$ 6.585 bytes
```
eLG2'_Ob
```
[Try it online!](https://fig.fly.dev/#WyJlTEcyJ19PYiIsIiJd)
Port of Vyxal
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 14 bytes
```
{#$x(10/2\)/2}
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs6pWVqnQMDTQN4rR1Deq5eJKUzfUVjQGAEsCBXk=)
Outputs the nth element.
Unfortunately, this can only do the first 3 elements because it's written in C, so overflow happens very quickly.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `l`, ~~8~~ ~~7~~ 5 bytes
```
2?(ΠE
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJsIiwiIiwiMj8ozqBFIiwiIiwiMTIiXQ==)
Outputs nth term
## Explained
```
2?(ΠE
2      # Push 2 to the stack
 ?(    # Input times:
   ΠE  #   push int(binary representation of top of stack)
       # the `l` flag pushes the length of the top of the stack
```
## Old 7 byter, outputs infinite sequence
```
2‡ΠEḞvL
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJQIiwiIiwiMuKAoc6gReG4nnZMIiwiIiwiMTIiXQ==)
## Explained
```
2‡ΠEḞẎvL
2‡  Ḟ    # an infinite generator that gets its next term by:
  ΠE     #   converting its previous term to binary and casting to int   
      vL # lengths of every item
```
[Answer]
# [Factor](https://factorcode.org/), 35 bytes
```
2 [ >bin dup length . dec> t ] loop
```
Prints the infinite sequence starting with 2. Times out on TIO, but here's a screenshot using the debugger to step through some of the starting iterations:
[![enter image description here](https://i.stack.imgur.com/AHnll.gif)](https://i.stack.imgur.com/AHnll.gif)
[Answer]
# [Sequences](https://github.com/nayakrujul/sequences), \$9 \log\_{256}(96)\approx\$ 7.4 bytes
```
2HE2hBnHz
```
### Explanation
```
2HE2hBnHz
  E        // Infinite sequence
2H         // Starting with 2
           // For each term:
   2hB     //   Convert to binary
      n    //   Interpret as integer
       H   //   And use this as the next term
        z  //   Get the length and output implicitly
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 10 bytes
```
L.BsbmlyF2
```
[Test suite](https://pythtemp.herokuapp.com/?code=L.BsbmlyF2&test_suite=1&test_suite_input=2%0A5%0A10&debug=0)
Prints the first \$n\$ terms.
The `m` can be omitted to instead print \$a(n)\$, where \$a(0)=2\$.
[Answer]
# [APL (dzaima/APL)](https://github.com/dzaima/APL), 19 bytes
```
{≢⍕(10⊥2∘⊥⍣¯1)⍣⍵⊢2}
```
[Try it online!](https://tio.run/##SyzI0U2pSszMTfz/P@1R24TqR52LHvVO1TA0eNS11OhRxwwg9ah38aH1hppA6lHv1kddi4xq/z/qmwpUnHZohaGCkYKxgomC6X8A "APL (dzaima/APL) – Try It Online")
Due to limits, this can also only output the first 5 elements.
This works in Dyalog too, but can only output the first 3 elements there.
[Answer]
# [Haskell](https://www.haskell.org/), ~~75~~ 63 bytes
```
g 2
g x=length(show$f x):g(f x)
f 0=0
f n=f(div n 2)*10+mod n 2
```
[Try it online!](https://tio.run/##FYtBbsIwEEX3nGIWXQTqSjMex/ZU8hF6AyQUAXGiJCYiqOX0NcPmv6@n/4dum67zXKd0rBnsLsMzzdeSH0OzDbe/jx6e@@/cvLHrARNqltQ3l/EXCtj9gfBzuV3evS7dWCDB0q0/J1jvY3nAVK1xhtAwaSoYlcKGvY2GLDoxDtGyIbbSknGOvIKcD6RbFwN70aUnQQxkWg7RWn1RiN5j8KqEnUQSdRKobSOz/J/7uctb/Tqv6ws "Haskell – Try It Online")
* Thanks to @Sʨɠɠan for saving 2 Bytes
*f n* returns a (decimal binary, length) tuple
[Answer]
# [Python](https://www.python.org), ~~56 47~~ 40 bytes
* -9 thanks to friddo.
* -7 thanks to loopy walt.
Outputs the infinite sequence, starting from 2. (Note: [apparently this is fine](https://codegolf.stackexchange.com/questions/253857/length-of-binary-as-base-10-oeis-a242347/253863#comment563886_253863))
```
i=2
while i:=f"{int(i):b}":print(len(i))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vwU2vzNyC_KISheLKYq78gqLMvBJbMMmVkpqmAGZpVGhacSlkpilU2BkagIEVULFeakVmiYaBJpdCPkzV0tKSNF2LmxqZtkZc5RmZOakKmVa2aUrVINlMTaukWiUriNKc1DygAFT9AigFpQE)
---
# [Python](https://www.python.org), ~~66~~ 59 bytes
* -7 thanks to loopy walt.
Suggested by friddo. Returns the first n terms.
```
lambda n,i=2:[1]+[len(i:=f"{int(i):b}")for _ in range(1,n)]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3rXMSc5NSEhXydDJtjayiDWO1o3NS8zQyrWzTlKoz80o0MjWtkmqVNNPyixTiFTLzFIoS89JTNQx18jRjoUbogOQSkeUUDA01rbgUCopABiTqKKjr2qnrKKRpJGpqQvQsWAChAQ)
---
# [Python](https://www.python.org), ~~74~~ 69 bytes
* -5 thanks to loopy walt.
Returns the nth term.
```
lambda n,i=2:len((['1']+[(i:=f"{int(i):b}")for _ in range(n-1)])[-1])
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3XXMSc5NSEhXydDJtjaxyUvM0NKLVDdVjtaM1Mq1s05SqM_NKNDI1rZJqlTTT8osU4hUy8xSKEvPSUzXydA01YzWjdQ1jNaGG6YBUJCJUGOooGBpqWnEpFBSBjEnUUVDXtVPXUUjTSNSE6lmwAEIDAA)
[Answer]
# PARI/GP 55 bytes
```
f(n)=k=2;d=digits;while(n--,k=fromdigits(d(k,2)));#d(k)
```
Stack of 8 GBytes overflows for n=18.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 67 bytes
```
q;b;v;f(n){for(v=2;n--;v=q)for(b=q=0;v;v/=2)q+=v%2*exp10(b++);q=b;}
```
[Try it online!](https://tio.run/##VVDZbsIwEHznK1aRkBKSCB@5LNd9qfoVhQdiHIoKgRxNUVF@vek6HC2WvN6ZnVl5V4cbrYehkrnsZOGW3rk41G6nmCzDUHaq8izOVaUICrq5Yl7lq27KZuZ0pMTNfd@TlcplP2zLFvarbel6cJ4AHkugyujWrN@WoODMAogCoCQATnsJ8zlYZCEnNhMc04RlmDMSCVQTwpCjnImYIoxoYl8aJSm1lihLeSKsPqGCkBRrMU8zxqyZplmSkDSxpOCRyKiwrEhpHGeci16O39SHsmlBv6/qGUajP0x9@a2zOL2yxUm84I2dAP5j7lzduB5w7aTbcm1OaCPymj5Bs/02h8K97cCD@Y2a3TkJvj/qb1u7ba7FXpdGPlD5UGqwVLit98gaZO/rHp3LP8GxRknhOtM1hM@AcdosSpypDaAJ7mM3SpnltW0/xtq0n3WJQ0364UcXu9WmGcKvIdztfwE "C (gcc) – Try It Online")
Inputs \$1\$-based \$n\$.  
Returns the \$n^{\text{th}}\$ element starting with \$a(1) = 2\$.
[Answer]
# [J](https://www.jsoftware.com), 18 bytes
```
[:#@":10x&(#.#:)&2
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70wa8FOJT31NAVbKwV1BR0FAwUrINbVU3AO8nFbWlqSpmuxKdpK2UHJytCgQk1DWU_ZSlPNCCKxS5MrNTkjXyFNQU3PDqjLUMFIwVjBRMFUwQyiYMECCA0A)
-2 thanks to Jonah!
[Answer]
# [Raku](https://raku.org/), ~~16~~ 30 bytes
```
map *.chars,(2,+*.base(2)...*)
```
[Try it online!](https://tio.run/##K0gtyjH7n1up4FCsYPs/N7FAQUsvOSOxqFhHw0hHW0svKbE4VcNIU09PT0vzv7VCcSJIZXScWex/AA "Perl 6 – Try It Online")
An expression for the lazy, infinite sequence of numbers.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~8~~ 7 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
‘ḊḌB$\Ẉ
```
A monadic Link that accepts a positive integer, \$n\$, and yields a list of the first \$n\$ terms.
**[Try it online!](https://tio.run/##y0rNyan8//9Rw4yHO7oe7uhxUol5uKvj////hgYA "Jelly – Try It Online")**
### How?
Performs each conversion step in the opposite order as it avoids the need to get lists again at the end.
Uses a reduce that only uses the left item at each step, starting with a list of length \$n\$ that starts with a \$2\$ as it saves a byte over collecting up \$n-1\$ times starting with a \$2\$.
```
‘ḊḌB$\Ẉ - Link: integer, n
‘       - increment (n) -> n+1
 Ḋ      - dequeue ([1..n+1]) -> [2..n+1]
     \  - reduce by:
    $   -   last two links as a monad - i.e. f(left):
 Ḍ      -     convert from decimal e.g. 2 -> 2     or [1,0,1,0] -> 1010
  B     -     convert to binary    e.g. 2 -> [1,0] or 1010 -> [1,1,1,1,1,1,0,0,1,0]
      Ẉ - length of each
```
[Answer]
# [Nibbles](http://golfscript.com/nibbles/index.html), 7.5 bytes (15 nibbles)
```
.`.2`@~``@$,`p
```
```
   2            # start with 2
 `.             # iterate while unique:
       ``@$     #   convert to bits
    `@~         #   and convert to base 10
.               # now, map over this infinite list
           ,    #   get lengths of
            `p  #   string representations
```
[![enter image description here](https://i.stack.imgur.com/xR5lK.png)](https://i.stack.imgur.com/xR5lK.png)
[Answer]
# [sclin](https://github.com/molarmanful/sclin), 21 bytes
```
"2""2X>b >S"itr"len"map
```
[Try it here!](https://replit.com/@molarmanful/try-sclin) Returns an infinite list.
For testing purposes (use `-i` flag if running locally):
```
; 10tk >A
"2""2X>b >S"itr"len"map
```
## Explanation
Prettified code:
```
"2" ( 2X>b >S ) itr \len map
```
* `"2" ( ... ) itr` generate infinite list starting from 2...
	+ `2X>b` to binary
	+ `>S` to string
* `\len map` get lengths of each element
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 17 bytes
```
≔2θＦＮ«⟦ＩＬθ⟧≔⍘Ｉθ²θ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/9@xuDgzPU9DyUhJR6FQ05orLb9IQcMzr6C0xK80Nym1SENTU6GaizOgKDOvRCPaObG4RMMnNS@9JEOjUFMzFqiBE2qCU2JxanAJUFm6BlhVoaaOgpEmxNDa//9N/@uW5QAA "Charcoal – Try It Online") Link is to verbose version of code. As we are outputting A242347, which starts with `1`, so does this version. Explanation:
```
≔2θ
```
Start with `2`.
```
ＦＮ«
```
Repeat `n` times.
```
⟦ＩＬθ⟧
```
Output its length on its own line.
```
≔⍘Ｉθ²θ
```
Cast it to decimal, then convert it to binary as a string.
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 45 bytes
```
.+
$*:2
{`:\d+
$*B
+`(B+)\1
$1A
AB
B
}T`L`d
.
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wX0@bS0XLyoirOsEqJgXEduLSTtBw0taMMeRSMXTkcnTicuKqDUnwSUjh0vv/34DLkMuIyxgA "Retina 0.8.2 – Try It Online") Outputs the 0-indexed `n`th term. Link includes test cases for `0` to `3` as higher values are too slow. Explanation:
```
.+
$*:2
```
Convert the input to unary as a number of `:`s and suffix a `2` for the zeroth value.
```
{`
}`
```
Repeat until the nth value has been found.
```
:\d+
$*B
```
If more terms are needed then convert the current value into unary as a number of `B`s.
```
+`(B+)\1
$1A
AB
B
```
If there are any `B`s then convert them to binary using `B` for `1` and `A` for `0`. This is done separately to avoid corrupting the final value.
```
T`@=`d
```
Convert the "binary" to normal digits.
```
.
```
Count the number of digits in the final value.
A008559 can be obtained at a saving of 3 bytes by deleting the last line and removing the `}`.
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 10 bytes
```
Y2LaP#TB:y
```
[Try It Online!](https://dso.surge.sh/#@WyJwaXAiLCIiLCJZMkxhUCNUQjp5IiwiIiwiIiwiMTAiXQ==)
Prints the first `a` terms in the sequence starting with 2, where `a` is the argument input.
```
Y2LaP#TB:y      ; a = input
Y2              ; Set y = 2
  La            ; Loop the following code "a" times...
    P#          ; Print the length of...
      TB:y      ; y treated as a decimal number converted to a binary string
                  and set y to that value
```
[Answer]
# [cQuents](https://github.com/stestoltz/cQuents), 9 bytes
```
Lb$
=2:JZ
```
[Try it online!](https://tio.run/##Sy4sTc0rKf7/3ydJhcvWyMor6v9/AA "cQuents – Try It Online")
Prints the entirely sequence infinitely starting with `1,2,4,10,31,100,330,...`
## Explanation
**First line**
```
       implicit : output the nth term if input is provided, or all terms in the sequence if no input provided
       each term in the sequence equals
L                                       length (                       )
 b                                               second line (       )
  $                                                            index
```
**Second line**
```
=2     first term in sequence is 2
  :    output the nth term in the sequence
       each term in the sequence equals
   J                                    base 2 of (                   )
    Z                                               the previous term
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 54 bytes
*-3 bytes thanks to [@Sʨɠɠan](https://codegolf.stackexchange.com/users/92689/s%ca%a8%c9%a0%c9%a0an)*
Prints the sequence indefinitely, starting at \$2\$ (as now allowed by the OP).
```
for(n=2;;console.log(n.length))n=BigInt(n).toString(2)
```
[Try it online!](https://tio.run/##BcExDoAgDAXQ67SDDKzExc3ZExDEiiG/BhqvX9978pdnGe21BXpW90sHYY0pFcXUXkNXIYReIXYzY92a7DACB9PDRoNQZPcf "JavaScript (Node.js) – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 6 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
Infinite sequence starting at `2`:
```
Tλb}€g
```
[Try it online.](https://tio.run/##yy9OTMpM/f8/5NzupNpHTWvS//8HAA)
Could be the infinite sequence starting at `1` by replacing `T` with `2`: `2λb}€g` - [try it online](https://tio.run/##yy9OTMpM/f/f6NzupNpHTWvS//8HAA).
Outputting the \$n^{th}\$ term is 6 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) as well with either `2λèb}g` ([try it online](https://tio.run/##yy9OTMpM/f/f6NzuwyuSatP//zcFAA)) or `2IFb}g` ([try it online](https://tio.run/##yy9OTMpM/f/fyNMtqTb9/38DAA));  
and outputting the first \$n\$ values is 7 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) with either `2λ£b}€g` ([try it online](https://tio.run/##yy9OTMpM/f/f6NzuQ4uTah81rUn//98UAA)) or `2IFbDg,` ([try it online](https://tio.run/##yy9OTMpM/f/fyNMtySVd5/9/UwA)).
**Explanation:**
```
 λ      # Start a recursive environment,
        # to output the infinite sequence
T       # Starting at a(0)=10
        # Where every following a(n) is calculated as:
        #  (implicitly push the previous term a(n-1))
  b     #  Convert it from a base-10 integer to a binary string
   }€   # After we have the infinite sequence: map over each binary string:
     g  #  Pop and push its length
        # (after which the infinite sequence is output implicitly)
```
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf/blob/master/math_golf.txt), 7 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py)
```
2æhpià∟
```
Prints the infinite sequence, starting from `1`.
[Try it online.](https://tio.run/##y00syUjPz0n7/9/o8LKMgszDCx51zP//HwA)
Outputting the first \$n\$ terms would be 8 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py) instead:
```
2kæhpià;
```
[Try it online.](https://tio.run/##y00syUjPz0n7/98o@/CyjILMwwusgWwuUy5DAwA)
**Explanation:**
```
2        # Push a 2
      ∟  # Do-while true (without popping),
 æ       # using 4 characters as inner code-block:
  h      #  Push the length (without popping)
   p     #  Pop and print it with trailing newline
    i    #  Convert the binary-string to a base-10 integer
     à   #  Convert that integer to a binary-string
```
The program for the first \$n\$ terms is pretty similar, except that `k` pushes the input-integer; `æ` acts as a loop that many times instead of the do-while loop; and `;` discards the final binary-string after the loop, which would otherwise have been output implicitly.
[Answer]
# [Perl 5](https://www.perl.org/) -Mbigint, 58 bytes
```
eval'$_=2;'.'$_=new Math::BigInt($_)->to_bin;'x$_;$_=y///c
```
[Try it online!](https://tio.run/##K0gtyjH9/z@1LDFHXSXe1shaXQ9E56WWK/gmlmRYWTllpnvmlWioxGvq2pXkxydl5lmrV6jEWwMVVerr6yf//2/IZcRlzGXCZcplxmXOZcFlyWVo8C@/oCQzP6/4v25Bjm9SZnpmXgkA "Perl 5 – Try It Online")
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 40 bytes
```
2:2(?v:2%$2,:1%-!
?v00.>lnao>l1)
.>a*+a1
```
[Try it online](https://tio.run/#%23S8sszvj/38jKSMO@zMpIVcVIx8pQVVeRy77MwEDPLicvMd8ux1CTS88uUUs70fD/fwA)
"Infinte sequence". Overflows at the 7th number.
[Answer]
# [Gaia](https://github.com/splcurran/Gaia), 11 bytes
```
)2¤U⟪¤bd⟫⊢l
```
[Try it online!](https://tio.run/##AR0A4v9nYWlh//8pMsKkVeKfqsKkYmTin6viiqJs//8xMA "Gaia – Try It Online") or [Try a test suite!](https://tio.run/##AUwAs/9nYWlh//8pMsKkVeKfqsKkYmTin6viiqJs/zpw4oCcIC0@IOKAnXDihpFxClsxIDIgMyA0IDUgNiA3IDggOSAxMCAyMF0g4oaRwqb/ "Gaia – Try It Online")
A sort of copy of the Jelly answer but in Gaia. Times out for >= 12 I think.
## Explained
```
)2¤U⟪¤bd⟫⊢l
)            # Increment the input
 2¤          # Push 2 "under" the incremented input by pushing 2 and then swapping
   U         # Push a range [2, input + 1] to the stack
    ⟪   ⟫⊢   # Reduce that list by:
     ¤b      #   Converting the last item to binary
       d     #   And then to decimal
         l   # Get the length of the result
```
[Answer]
# [Pyt](https://github.com/mudkip201/pyt), 8 bytes
```
2`ĐąŁƥɓł
```
[Try it online!](https://tio.run/##K6gs@f/fKOHIhCOtRxuPLT05@WjT//8A "Pyt – Try It Online")
Prints indefinitely.
```
2           push 2
 `     ł    do... while top of stack is truthy
  Đ         Đuplicate
   ą        convert to ąrray of digits
    Łƥ      ƥrint Łength
      ɓ     convert to ɓinary string (implicitly treats output as decimal number)
```
]