g | x | w | all
Bytes Lang Time Link
120CASIO BASIC CASIO fx9750GIII250425T164415Zmadeforl
158Tcl250520T095533Zsergiol
003Vyxal210705T095910Zemanresu
051R240607T193429Zpajonk
011Pip240606T215649ZDLosc
075R240606T151123ZGlory2Uk
129Rust211106T041816Zcg909
089AWK210706T021646Zcnamejj
008Japt201019T111332ZShaggy
005Husk201018T155514ZLegionMa
108Java JDK200319T100743ZOlivier
075Perl 5 n200319T132255Zandytech
087Bash + GNU utilities200319T061230ZMitchell
058Ruby200319T063736ZG B
079C gcc200319T015935Zxibu
007APL dzaima/APL200319T012018ZBubbler
072Wolfram Language Mathematica200318T123423ZZaMoC
00405AB1E200318T210541ZJonathan
091C gcc200318T140511ZNoodle9
nanPHP200318T154042ZGuillerm
053Python 3200318T111915ZNoodle9
068Ruby200318T144117ZIMP1
131Red200318T140815ZGalen Iv
024APL Dyalog Unicode200318T123853ZAviFS
00605AB1E200318T112840Zuser9206
00405AB1E200318T130722ZDorian
010J200318T123324ZGalen Iv
025APL+WIN200318T122853ZGraham
052Python 2200318T112320ZSurculos
004Jelly200318T115621ZRGS
055JavaScript ES6200318T111234ZArnauld
011Charcoal200318T112237ZNeil

CASIO BASIC (CASIO fx-9750GIII), 148 120 bytes

For 1→N To ᴇ2
Int logab(2,N→E
Seq((N Int÷ 2^(E-K)) Rmdr 2,K,0,E,1→List1
Sum List1→H
0
For 0→K To E
List1[K+1→U
H-U→H
Ans+U₁₀H(Int (10Frac N⌟₁₀(1+(K-1) Rmdr (1+Int Log N
Next
Ans◢
Next

if you need a super-rough explanation, heres my crude and lazily put together attempt at transcribing it to LaTeX:

$$ f(N)=\sum_{k=0}^{\left\lfloor\log_2N\right\rfloor}(o(k+1,N)10^{\text{popcount}(N)-{o_{cuml}(k+1,N)}}\times\left\lfloor 10\times\text{frac}(\frac{N}{10^{(1+(k-1 \mod (1+\left\lfloor\log_{10}N\right\rfloor)))}})\right\rfloor).\\ o(x,y)=\left\lfloor \frac{y}{2^{\left\lfloor\log_2y\right\rfloor-x}} \right\rfloor.\\ o_{cuml}(x,y) = \text{cumulative sum of }o(x,y)\text{ while }y=N. $$ if you can, PLEASE make this better. I know next to nothing about LaTeX and it's the only way I know how to explain my CASIO BASIC code

Tcl, 158 bytes

proc X n {join [lmap x [split [string ra [string repe $n [set l [string le [set b [format %b $n]]]]] 0 $l-[expr $n>9]] ""] y [split $b ""] {if $y set\ x}] ""}

Try it online!

Vyxal, 3 bytes

bTİ

Try it Online!

So, when attempting to interpret an integer as a list, Vyxal will often cast it to a list of digits. This behaviour is almost never particularly useful, especially compared to casting said integer to a range, but here this somewhat questionable language design choice results in a 3-byte solution.

b   # Binary digits of input
 T  # Find indices of 1s
  İ # Index those into [digits of] input

R, 51 bytes

\(n,`+`=\(b)n%/%b^rev(0:log(n,b))%%b)(+2*+10)[+2>0]

Attempt This Online!

Pip, 11 bytes

a@_X BMETBa

Attempt This Online!

Explanation

a@_X BMETBa
          a  ; Command-line argument
        TB   ; Convert to binary
      ME     ; Map this function to each (index, value) pair:
  _          ;   The index
a@           ;   Character at that index (wrapping) in the original argument
   X         ;   Repeat
     B       ;   0 or 1 times depending on the digit value
             ; Concatenate and print (implicit)

R, 75 bytes

\(x,b=bitwAnd(x,e<-2^((log(x,2)%/%1):0))/e)(utf8ToInt(c(x,""))-48+0*b)[!!b]

Attempt This Online!

A function which inputs a number \$x\$ and outputs the \$x^{\text{th}}\$ sequence member.

Binary conversion was inspired by this SO answer.

Rust, 131 129 bytes

|n|format!("{:b}",n).chars().zip(format!("{}",n).chars().cycle()).flat_map(|(b,c)|if'0'<b{Some(c)}else{None}).collect::<String>()

Try it online!
Try it online!

Works according to option 1 and returns the \$n^{\text{th}}\$ number of the sequence as a string.

-2 thanks to Kevin Cruijssen!

Explanation

|n|                  // Closure taking a parameter n
format!("{:b}",n)    // Binary string of n
.chars()             // Iterate over the chars
.zip(                // Zip iterator with
  format!("{}",n)    //   Decimal string of n
  .chars().cycle()   //   Cycle over the chars
)
.flat_map(           // Map with the following iterator-returning
                     // function and flatten the result
  |(b,c)|            //   Closure taking the char pairs (b,c)
  if'0'<b{Some(c)    //   If '1' then return an iterator yielding c
  else{None}         //   Else return an empty iterator
)
.collect::<String>() // Evaluate into a string

AWK, 89 bytes

{for(f=b=1;$1>=b;e=e$1)c[d++]=and($1,b)/(b*=2);for(;d--;f++)c[d]?g=g substr(e,f,1):0}$0=g

Try it online!

Not that short, but AWK doesn't have a print format to generate binary strings from integers, so it has to iterate to get that info...

At a high level, one loop uses bitwise and operations with a single bit moved one position to the left each time to built an array of "binary" settings. It also builds up a string composed of multiple copies of the N number while it's looping. AWK doesn't have a nice string*number operator either.

Then the second loop works backwards through that array and for each entry which is 1, it appends the appropriate character to a "results" accumulator.

The final step just prints the accumulated string.

# Loop 1, build the "binary" array and string of duplicated "N" characters
for(f=b=1;$1>=b;e=e$1)c[d++]=and($1,b)/(b*=2);
   (f=b=1;                                     # Loop init, "f" is used in loop #2
          $1>=b;                               # Exit test, goes until bit check > N
                e=e$1)                         # End of loop, build "N dup string
                      c[d++]=and($1,b)/(b*=2); # Body, does a couple of things...
                                               # d++ : increment bit position
                                               # and($1,b) : extract bit
                                               # /(b*=2) : normalize, then shift bit
                                               # c[d++]= : add to "binary" array

# Loop 2, accumulate chars associated with set bits
for(;d--;f++)c[d]?g=g substr(e,f,1):0
     d--;                             # Exit test, when all bits checked stop
         f++)                         # End of loop, increment char pos in "N" dup str
             c[d]?                 :  # Ternary, code runs if bit is set
                  g=g substr(e,f,1)   # Append current char to accumulator
                                    0 # No-op "else" from ternary

# Print the result
$0=g   # Typical AWK golf trick, assign "$0" to what you want to print w/o code block

Japt, 8 bytes

Came up with a few approaches but couldn't do better than 8 bytes.

With output as a digit array:

¤¬ðÍ£sgX

Try it

With output as a string:

¤ËÍçEgUs

Try it

¤¬ðÍ£sgX     :Implicit input of integer U
¤            :To binary string
 ¬           :Split
  ð          :Truthy indices when
   Í         :  Converted to integer
    £        :Map each X
     s       :  Convert U to string
      gX     :  Get digit at index X
¤ËÍçEgUì     :Implicit input of integer U
¤            :To binary string
 Ë           :Map each D at index E
  Í          :  Convert D to integer
   ç         :  That many times repeat
    Eg       :  Index E into
      Uì     :  Digit array of U

Husk, 5 bytes

fḋ¹¢s

Try it online! This function works according to option 1, outputting the term as a string.

Explanation

fḋ¹¢s  (Let X denote the argument.)
f      Select the elements of
    s    the string representing X,
   ¢    cycled infinitely, corresponding to truthy values of
 ḋ¹     the binary digits of X.

Java (JDK), 108 bytes

n->{var s=""+n;for(int b=n.highestOneBit(n),i=0;b>0;b/=2,i++)if((b&n)>0)System.out.print((s+=s).charAt(i));}

Try it online!

Credits

Perl 5 -n, 75 bytes

map{$i=0;@b=split//,sprintf"%b",$_;say@s=grep{$b[$i++]}split//,$_ x@b}1..$_

Try it online!

Prints the first n numbers in the sequence

Perl 5 -nl, 60 bytes

@b=split//,sprintf"%b",$_;say@s=grep{$b[$i++]}split//,$_ x@b

Try it online!

Shorter version that just prints the nth number

Bash + GNU utilities, 87 bytes

x=$1$1$1$1
for((b=`dc<<<2o$1p`;b;)){ [ $[b] = $b ]&&printf ${x:0:1};x=${x:1};b=${b:1};}

Try the test suite online!

Input \$n\$ is passed as an argument, and the \$n^\text{th}\$ number in the sequence is output on stdout.

How it works:

x is set to 4 copies of the input in a row, which is more than enough digits to match the binary equivalent of the input. (A number in base 2 can never be longer than 4 times its representation in base 10, since \$\log_2(10)<4.\$)

b is initialized to the binary representation of the input.

The for loop repeats the following as long as b still has at least one 1 in it:

The golfiest trick is probably the way I check to see if b starts with a 1: the expression $[b] means: b evaluated as an arithmetic expression. This will omit any initial 0s (except that it will keep a final 0 if all the characters in b are 0). So [ $[b] = b ] is true iff b either starts with a 1 or is equal to "0". But b can't equal "0" since the loop termination condition would have been true in that case, and the loop would have ended already.

Ruby, 58 bytes

->n{a=n.digits 2;([n]*n*m='').chars{|x|m<<x*(a.pop||0)};m}

Try it online!

C (gcc), 79 bytes

V;M;r(n){M<=V?r(n/10?:(M*=2,V)),M/=2,M&V&&putchar(n%10+48):0;}f(n){M=1;r(V=n);}

Try it online!

Generates the nth number

APL (dzaima/APL), 7 bytes

⊤⌿≢∘⊤⍴⍕

Try it online!

How it works

⊤⌿≢∘⊤⍴⍕  ⍝ Input: n
  ≢∘⊤    ⍝ Length of base-2 digits
     ⍴⍕  ⍝ Repeat the digits of n (as a string) to the length of above
⊤⌿       ⍝ Take the digits where the corresponding base-2 digit is 1

APL (Dyalog Unicode), 16 bytes

⍕(∊⊢⊆⍴⍨∘≢)2∘⊥⍣¯1

Try it online!

How it works

⍕(∊⊢⊆⍴⍨∘≢)2∘⊥⍣¯1  ⍝ Input: n
          2∘⊥⍣¯1  ⍝ Binary digits of n
⍕                 ⍝ Stringify n
 (       )        ⍝ Inner function with the two args above
       ∘≢         ⍝ Length of binary digits
     ⍴⍨           ⍝ Cycle the string digits to the length
  ∊⊢⊆             ⍝ Filter the digits by the binary digits

Wolfram Language (Mathematica), 72 bytes

Pick[Flatten[(i=IntegerDigits)/@Table[#,s=Length[p=#~i~2]]][[;;s]],p,1]&

Try it online!

Here is the plot of the first 30.000 such numbers

enter image description here

And here is the Logarithmic plot

enter image description here

05AB1E, 4 bytes

∍IbÏ

Try it online!

How?

∍IbÏ - Full program expecting a single input      e.g. 13    stack:
∍    - extend a to length b (stack empty so a=b=input)       [1313131313131]
 I   - push the input                                        [1313131313131, 13]
  b  - convert to binary                                     [1313131313131, 1101]
   Ï - a where b is 1                                        [133]
     - implicit output                                       133

C (gcc), 101 \$\cdots\$ 96 91 bytes

Save a 6 bytes thanks to ceilingcat!!!

b;i;f(n){char s[n];for(b=1;i=n/b;b*=2);for(;b/=2;++i)b&n&&putchar(s[i%sprintf(s,"%d",n)]);}

Try it online!

Outputs the \$n^{\text{th}}\$ number in the sequence.

PHP, 75 86 81 73 bytes

for(;$i<strlen($d=decbin($a=$argn));$i++)if($d[$i])echo$a[$i%strlen($a)];

Try it online!

Gives the nth number.

Original version didn't handle 0's in input correctly.

Python 3, 80 \$\cdots\$ 52 53 bytes

Saved a 2 bytes thanks to Jitse!!!
Saved 7 6 bytes thanks to Surculose Sputum!!!
Added a byte to fix bugs kindly point out by Jitse and Surculose Sputum.

lambda n:[c for c,d in zip(str(n)*n,f'{n:b}')if'0'<d]

Try it online!

Returns the \$n^{\text{th}}\$ number in the sequence as a list of digits.

Ruby, 68 bytes

->n{n.to_s(2).gsub(/./).with_index{|b,i|b>?0?(n.to_s*n)[i]:""}.to_i}

Try it online!

Returns the nth number in the sequence.


I'm no expert golfer, so it's undoubtedly possible there's a better Ruby solution, but I'm (not altogether unpleasantly) surprised to see a challenge where Python and JavaScript both outperform Ruby. I guess python's list comprehensions are a perfect fit for this challenge, and JavaScript passing the index as a parameter to the replace method is very convenient.

Red, 131 bytes

func[n][i: 0 remove-each _ t: take/part append/dup t: to""n n |:
length? s: find to""enbase/base to#{}n 2"1"|[s/(i: i + 1) =#"0"]t]

Try it online!

APL (Dyalog Unicode), 25 24 bytes

Code

{b←2∘⊥⍣¯1⋄(b⍵)/(⍴b⍵)⍴⍕⍵}

Try it online!

Explanation

{                                        ⍝ Start function definition
  b ← 2∘⊥⍣¯1                             ⍝ Let b ← binary conversion function
              ⋄                           ⍝ Start new clause
                (b⍵)                      ⍝ Binary representation of ⍵ (input)
                     /                    ⍝ Mask boolean list over following string
                       (⍴b⍵)              ⍝ Length of boolean representation of ⍵
                             ⍴            ⍝ Reshape
                                ⍕⍵        ⍝ Stringify ⍵
                                    }     ⍝ End function definition



Binary Conversion

This is all much longer than one would expect from APL and is due to the lack of a concise binary conversion function. Unfortunately, the above is the best we can do. Below is the breakdown:

Together, 2∘⊥⍣¯1 denotes the inverse of the function that converts from binary to decimal.
(Two left-curried with the encoding function, 2∘⊥, converts binary to decimal.)

05AB1E, 6 bytes

The Ï< ruins the consecutive word bāsè... (If you don't get it, the hex code 05AB1E converted to base64 would result in base.)

bāsÏ<è

Try it online!

Explanation

b      To base 2
 ā     Length-range to 1
  s    Prepend
   Ï   Keep all that's truthy
    <  -1 due to 0-based indexing ... that's terrible!
     è Modular Indexing

05AB1E, 4 bytes

×IbÏ

Try it online!

Yeah, I found the mysterious 4-byte 05AB1E answer :D

×   expand the input digits (input 123 -> 123123123123123... )
Ib  get the binary value of input (123 -> 1111011)
Ï   keep only the digits where the corresponding binary digit is 1

J, 13 10 bytes

#:##@#:$":

Try it online!

APL+WIN, 25 bytes

Prompts for integer n and outputs nth term

((b⍴2)⊤n)/(b←1+⌊2⍟n)⍴⍕n←⎕

Try it online! Coutesy of Dyalog Classic

Python 2, 52 bytes

lambda n:[c for c,i in zip(`n`*n,bin(n)[2:])if'0'<i]

Try it online!

Input: An integer \$n\$
Output: The \$n^{th}\$ numbers in the sequence, in the form of a list of digits.

How:

Jelly, 4 bytes

BTịD

Try it online, code that computes the \$n\$th term of the sequence, or check the first 100 terms!

How it works:

B     convert number to binary, i.e. 5 -> [1, 0, 1]
 T    keep the indices of the Truthy elements, i.e. [1, 0, 1] -> [1, 3]
  ị   and then index safely into...
   D  the decimal digits of the input number

By "index safely" I mean that indices out of range are automatically converted into the correct range!

JavaScript (ES6), 55 bytes

n=>n.toString(2).replace(/./g,(d,i)=>+d?(n+=[n])[i]:'')

Try it online!

Commented

n =>               // n = input
  n.toString(2)    // convert n to a binary string
  .replace(        // replace:
    /./g,          //   for each
    (d, i) =>      //   digit d at position i:
      +d ?         //     if d is '1':
        (n += [n]) //       coerce n to a string (if not already done)
                   //       and double its size to make sure we have enough digits
        [i]        //       extract the i-th digit
      :            //     else:
        ''         //       discard this entry
  )                // end of replace()

Charcoal, 11 bytes

⭆↨Iθ²⎇ι§θκω

Try it online! Link is to verbose version of code. Explanation:

   θ        Input as a string
  I         Cast to integer
 ↨  ²       Convert to base `2`
⭆           Map over digits
      ι     Current digit
     ⎇      If non-zero
        θ   Input as a string
       §    Cyclically indexed by
         κ  Current index
          ω Else empty string