text:
Expand some number
This challenge is based on this Stackoverflow question.
With a positive number as input, output it as the sum of each digit multiplied by its power-of-10 representation.
Input
A number, as an integer, a string or a list of digits/characters.

The number will be strictly positive.
If you accept the number as a string or list, it will not start with a 0.

Output
A string representing a sum of each relevant base-10 digits, each multiplied by its respective base-10 power. A sum is represented as a + b. You may use up to one space around each side of the + sign if you want. The operands are listed in descending order.

0 can never be a valid operand.
The + sign (surrounded or not by spaces) may not be the leading or trailing part.

Examples
Input       Output
12          10 + 2
         or 10+2
         or 10 +2
         or 10+ 2
9           9
123         100 + 20 + 3
10          10
101         100 + 1

Invalid outputs
2           1 + 1
10          10 + 0
1           0 + 1
12          + 10 + 2
12          10 + 2 +
12          2 + 10

This is code-golf so the shortest code in bytes wins!

Sandbox

Related

Can we output the sum in reverse? Ex. 123 = 3+20+100

@Quintec No: "The operands are listed in descending order." This is also shown as the last example of the "invalid output" section.

Ah, I missed the last one, gotcha. Might want to put that restriction under the output heading anyway

@Quintec It is, since the start of the challenge ;-)

Closely related

are leading and trailing spaces allowed?

@ngn yes, as many as you want!

What is the expected output for input 0? (If 0 is an invalid input in the first place, then it should be removed from the invalid output examples IMO)

@PedroA Indeed! I updated the challenge.

may my input be a reversed list of digits (e.g. 123->[3,2,1]) or do i need to keep them in order? (123->[1,2,3])

@hakr14 You need to keep in order. If I'd allowed that, you'd have to test [0,1] for 10, but the rules state: "[the list] will not start with a 0.", and here the list would effectively start with a 0. So I don't allow that.

Python 3: 83 80 79 Bytes
Try It Online!
My first Code Golf submission.
t=input();x=len(t);print(*[t[i]+'0'*(x+~i)for i in range(x)if'0'<t[i]],sep='+')

-3 Bytes by ovs. Thank you for that useful tip :)
-4 Bytes by mypetlion. Thank you for that shortening tip :)

Welcome to PPCG! You can improve your score by reordering your if statement to if'0'<t[i] and change your formula from x-i-1 to x+~i. Here is a TIO link with step by by step changes.

Change the print statement to print(*[t[i]+'0'*(x+~i)for i in range(x)if'0'<t[i]],sep='+') to save 1 byte.

Jelly, 9 bytes
ḊƬḌQIAj”+

Try it online!
How it works
ḊƬḌQIAj”+  Main link. Argument: A (digit array)

 Ƭ         Til; apply the link to the left until the results are no longer unique.
           Return all unique results.
Ḋ              Dequeue; discard the first element.
           For input [1,2,0,4], this yields [[1,2,0,4], [2,0,4], [0,4], [4], []].
  Ḍ        Undecimal; convert the digit arrays into integers.
           For input [1,2,0,4], this yields [1204, 204, 4, 4, 0].
   Q       Unique; deduplicate the resulting integers.
           For input [1,2,0,4], this yields [1204, 204, 4, 0].
    I      Increments; yield the forward differences.
           For input [1,2,0,4], this yields [-1000, -200, -4].
     A     Absolute value.
      j”+  Join with separator '+'.

Smart approach!

JavaScript (ES6), 47 bytes
Takes input as an integer.
f=(n,m=1,k=n%m)=>n-k?f(n-k,m*10)+(k?'+'+k:''):n

Try it online!
Commented
f = (                     // f is a recursive function taking:
  n,                      //   n = number to process
  m = 1,                  //   m = modulo (a power of 10, starting at 1)
  k = n % m               //   k = n mod m
) =>                      //
  n - k ?                 // if n is not equal to k:
    f(n - k, m * 10)      //   do a recursive call with n - k and m * 10
    + (k ? '+' + k : '')  //   if k is not zero: append '+' and k
  :                       // else:
    n                     //   append n and stop recursion

R, 55 bytes
Assuming integers are all under 1e10, which is larger than the maximum 32 bit integer anyway...
function(n,p=10^(9:0),x=p*n%/%p%%10)cat(x[!!x],sep='+')

Try it online!

Well, 10^(nchar(n):1-1 would theoretically work for any integer...

It would, but look at all those extra bytes!

Shakespeare Programming Language, 807 806 805 804 bytes
,.Ajax,.Ford,.Page,.Act I:.Scene I:.[Enter Ajax and Ford]Ford:Listen tothy!Scene V:.Ajax:Remember the remainder of the quotient between I twice the sum of a cat a big big cat.You be the sum of you a cat.Ford:You be the quotient between you twice the sum of a cat a big big cat.Be you nicer zero?If solet usScene V.You be I.Scene X:.Ajax:Recall.Be you worse a cat?If solet usScene D.[Exit Ford][Enter Page]Ajax:Be you nicer zero?If sospeak thy.You be the sum of a big big big big cat the cube of the sum of a cat a big cat.[Exit Page][Enter Ford]Ajax:Open heart.Remember I.You zero.Scene L:.Ajax:Am I nicer a cat?If notlet usScene C.Open heart.Ford:You be the sum of you a pig.Let usScene L.Scene C:.Ajax:Recall.Ford:You be I.Scene D:.Ford:You be the sum of you a pig.Be you nicer zero?If solet usScene X.

Try it online!
-23 bytes if a null character may be output first
,.Ajax,.Ford,.Page,.Act I:.Scene I:.[Enter Ajax and Ford]Ford:Listen tothy!Scene V:.Ajax:Remember the remainder of the quotient between I twice the sum of a cat a big big cat.You be the sum of you a cat.Ford:You be the quotient between you twice the sum of a cat a big big cat.Be you nicer zero?If solet usScene V.You be I.Scene X:.Ajax:Recall.Be you worse a cat?If solet usScene D.[Exit Ford][Enter Page]Ajax:Speak thy.You be the sum of a big big big big cat the cube of the sum of a cat a big cat.[Exit Page][Enter Ford]Ajax:Open heart.Remember me.You zero.Scene L:.Ajax:Am I nicer a cat?If notlet usScene C.Open heart.Ford:You be the sum of you a pig.Let usScene L.Scene C:.Ajax:Recall.Ford:You be I.Scene D:.Ford:You be the sum of you a pig.Be you nicer zero?If solet usScene X.

Explanation
,.Ajax,.Ford,.Page,.Act I:.Scene I:.[Enter Ajax and Ford]

    Boilerplate, introducing the characters.

Ford:Listen tothy!

    Input a value to Ajax.

Scene V:.Ajax:Remember the remainder of the quotient between I twice the sum of a cat a big big cat.You be the sum of you a cat.Ford:You be the quotient between you twice the sum of a cat a big big cat.Be you nicer zero?If solet usScene V.

    Push the digits of Ajax onto Ford's stack, and set Ford's value to be the number of digits in Ajax.

You be I.

    Store the number of digits in the input to Ajax.

Scene X:.Ajax:Recall.Be you worse a cat?If solet usScene D.

    Pop the next digit off the stack, and skip processing it if it equals 0.

[Exit Ford][Enter Page]Ajax:Be you nicer zero?If sospeak thy.You be the sum of a big big big big cat the cube of the sum of a cat a big cat.[Exit Page][Enter Ford]

    All characters start out with a value of 0.
    If Page is 0, that means this is the first number being processed, and we shouldn't output a plus.
    In either case, store the ASCII value of "+" to Page to output next time it is needed.

Ajax:Open heart.Remember I.You zero.

    Output the digit, save the remaining-digit-count for later, and store 0 to Ford for output purposes.

Scene L:.Ajax:Am I nicer a cat?If notlet usScene C.Open heart.Ford:You be the sum of you a pig.Let usScene L.

    Output one fewer 0 than the number of remaining digits to process.

Scene C:.Ajax:Recall.Ford:You be I.

    Store the remaining-digit-count back into Ajax.

Scene D:.Ford:You be the sum of you a pig.Be you nicer zero?If solet usScene X.

    Subtract 1 from the remaining-digit-count, and loop back until there are no more digits left to process.

Python 2, 64 bytes
f=lambda s='',*x:s and(s>'0')*(s+'0'*len(x)+(f(*x)and'+'))+f(*x)

Try it online!

Python 2, 66 bytes
f=lambda n,m=1:n>10and f(n/10,m*10)+(n%10>0)*('+'+`n%10*m`)or`n*m`

Try it online!

Jelly,  12  11 bytes
J’⁵*Ṛ×ḟ0j”+

A full program accepting the number as a list of digits (in Python format) which prints the result.
Try it online!
How?
J’⁵*Ṛ×ḟ0j”+ - Main Link: list of digits  e.g. [1,0,2,0,3,0]
J           - range of length                 [1,2,3,4,5,6]
 ’          - decrement (vectorises)          [0,1,2,3,4,5]
  ⁵         - literal 10                      10
   *        - exponentiate (vectorises)       [1,10,100,1000,10000,100000]
    Ṛ       - reverse                         [100000,10000,1000,100,10,1]
     ×      - multiply (vectorises)           [100000,0,2000,0,30,0]
      ḟ0    - filter discard zeros            [100000,2000,30]
        j”+ - join with '+'                   [100000,'+',2000,'+',30]
            - implicit (smashing) print       "100000+2000+30"

Previous @12 bytes:
Ḣ;0€ƊÐƤẸƇj”+

Haskell, 60 54 bytes
Edit: -6 bytes thanks to  Delfad0r.
tail.(>>=('+':)).filter(>="1").scanr((.('0'<$)).(:))""

Takes the input number as a string.
Try it online!
    scanr(        )""    -- starting with the empty string fold from the right and
                         -- collect the intermediate results in a list
      (.('0'<$)).(:)     -- non pointfree: \d s -> d : ('0'<$s)
                         -- i.e. take the next digit 'd' and append the current result
                         -- from the scanr where each char is replaced by 0
                         --
                         -- e.g. "103" -> ["100","00","3"]
                         --
  f ilter(>="1")         -- keep only elements that have not a 0 as the first char
 (>>=('+':))             -- prepend a + to each element and flatten into
                         -- a single list
tail                     -- drop the first char, ie.e the leading +

tail.(>>=('+':)).filter(>="1").scanr((.('0'<$)).(:))"" saves 6 bytes Try it online!.

@Delfad0r: nice, thanks a lot!

05AB1E, 10 bytes
Straight forward implementation.
Input as list of digits.
āR<°*0K'+ý

Try it online!
Explanation
    *        # multiply each digits in the input with
āR<°         # 10^(len(input)-1-index)
     0K      # remove results that are zero
       '+ý   # merge on "+"

Haskell, 56 55 52 bytes
-4 byte thanks to nimi.
tail.f
f('0':x)=f x
f(d:x)='+':d:('0'<$x)++f x
f x=x

Try it online!

explanation
g :: String -> String

-- drop the first char (the leading +) from f
g = tail.f

f :: String -> String

-- if the first digit is 0, continue with the rest of the number
f ( '0' :rest) = f rest

-- otherwise, add a +, the digit and as many 0s as there are digit in the rest.
f (digit:rest) = '+' : digit : ('0' <$ rest) ++ f rest

-- if there is no digit left, return the empty string
f "" = ""

Try it online!

Python 2, 82 73 71 bytes
-9 bytes thanks to @ovs
-2 bytes thanks to @JonathanAllan
lambda n:'+'.join(v+'0'*(len(`n`)-i)for i,v in enumerate(`n`,1)if'0'<v)

Try it Online

Python 2, 64 bytes
lambda n:'+'.join(`b`+~e*'0'for e,b in enumerate(n,-len(n))if b)

An unnamed function which takes a list of digits, n, and returns a string.
Try it online!
enumerate(n) would yield tuples of index, item across n with an index starting at 0.
However enumerate also takes an optional starting index as its second argument, by setting this to -len(n) we get indices (es) of -len(n), -len(n)+1, ..., -1.
This means the number of required trailing zeros for any item (b) is -1-e, which is ~e so  ~e*'0' gets the required trailing zeros.
`b` gets a string representation of the integer digit b and + concatenates this with those zeros.
if b filters out the entries with b==0.
'+'.join(...) then joins the resulting strings up with + characters.

Perl 6, 38 bytes
{join '+',grep +*,($_ Z~[R,] 0 Xx^$_)}

Try it online!
Anonymous code block that takes a list of digits and returns a string.
Explanation:
{                                    }  # Anonymous code block
                   $_ Z~   # Zip concatenate the list of digits with
                        [R,] 0 Xx^$_   # The correct number of 0s

          grep +*,(                 )  # Filter out all all the 0 values
 join '+',   # And join with '+'s

Brachylog, 35 32 bytes
l⟧₅;?z{tℕ₁I&h;10↔^;I×ṫ}ˢ;"+"zckc

-3 bytes cause 0 isn't a valid input
Try it online!  or testsuite
Explanation
                                    #   implicit input          eg  105
l                                   #   length of input             3
 ⟧₅                                 #   descending range ]n,0]      [2, 1, 0]
   ;?                               #   pair with input             [[2, 1, 0], [105]]
     z                              #   zip (considers numbers as array of digits)
                                    #                               [[2, 1], [1, 0], [0, 5]]
      {               }ˢ            #   select (map and filter)     [2, 1]  |   [1, 0]  |   [0, 5]
       t                            #       tail (last element)     1       |   0       |   5
        ℕ₁                          #       is at least 1           1       |   fail    |   5
          I                         #       store in I
           &h                       #       head of input           2       |           |   0
             ;10↔                   #       pair with 10 & reverse  [10, 2] |           |   [10, 0]
                 ^                  #       power                   100     |           |   1
                  ;I                #       pair with I             [100, 1]|           |   [1, 5]
                    ×               #       multiply                100     |           |   5
                     ṫ              #       to string               "100"   |           |   "5"
                        ;"+"        #   pair with "+"               [["100", "5"], "+"]
                            z       #   zip (cycles shorter)        [["100", "+"], ["5", "+"]]
                             c      #   concat (flattens)           ["100", "+", "5", "+"]
                              k     #   knife (remove last)         ["100", "+", "5"]
                               c    #   concat                      "100+5"

The OP has now specified that 0 is not an input you have to handle, so you can remove the |∧Ṡ from the end. :)

APL(Dyalog), 46 41 40 bytes
{¯1↓∊{'0'=⊃⍵:⍬⋄⍵}¨⍵,¨('0'⍴⍨¨⌽⍳≢⍵),¨'+'}

-5 bytes thanks to @dzaima
Anonymous prefix function. Takes input as a string. TIO
(This is my first time using APL on PPCG, probably golfable. Also, curse you, zeroes!)

41 bytes with ⎕IO←0

Retina, 19 bytes
|'+L$`[1-9]
$&$.'*0

Try it online! Link includes test cases. Explanation:
L`[1-9]

List all non-zero digits
$
$&$.'*0

For each digit, append as many zeros as there were trailing digits.
|'+

Separate each result with +s instead of the default newline.
Retina 0.8.2, 21 bytes
M&!`[1-9].*
\B.
0
¶
+

Try it online! Link includes test cases. Explanation:
M&!`[1-9].*

List all suffixes of the input that begin with non-zero digits.
\B.
0

Replace all trailing digits with zeros.
¶
+

Join the results with +s.

C (gcc), 71 69 bytes
Each step of the recursive function subtracts the part that it will print and passes the rest of the number on.
Thanks to ceilingcat for the suggestion.
g(v,c,w){v&&printf("+%d"+!g(v-w,c*10)+!w*3,w=v%c);w=v;}f(v){g(v,10);}

Try it online!

Brachylog v2, 15 bytes
~+bᵛ⁰↔;"+"zckwᵐ

Try it online!
Very, very inefficient.
Somehow, this manages to use only 6 bytes on what is in most languages the hard part (splitting the number into the form a10b where a is a single digit, in descending order), and a whole 9 bytes for the "join with +" (which is a builtin in most golfing languages, but not Brachylog).
Unlike most of my Brachylog submissions (which are functions), this one's a full program, taking input from standard input and producing output on standard output.
Explanation
~+bᵛ⁰↔;"+"zckwᵐ
~+               Find an additive partition of the input number
   ᵛ               such that each component of the partition,
  b                when the first digit is removed
    ⁰              is equal to 0;
     ↔           reverse it,
      ;"+"z      pair every element with "+",
           c     flatten the resulting list one level,
            k    remove the last element (i.e. the final "+"),
             w   and print
              ᵐ  each remaining element.

(The reason wᵐ is used rather than the more normal c is that we're dealing with a heterogenous list – it contains both numbers and strings – and rather than allowing these to mix, it's simplest to just print them all individually.)
The algorithm here brute-forces over all additive partitions of the input until it finds a suitable one (!). Brachylog favours partitioning into fewer possibilities, and with the possibilities sorted in ascending order, so the first solution it will find is the reverse of the solution that the question is asking for. So we just have to reverse it to get the solution we want.

Pip, 17 bytes
FI(REE,#a)*^aJ:'+

Attempt This Online!
Explanation
Different approach from my earlier 21-byte answer in Pip Classic:
FI(REE,#a)*^aJ:'+
      ,#a          Range(length(input number))
    EE             10 to the power of each element of the range
   R               Reversed
  (      )*        Multiply each element of that list by
           ^a      The corresponding element in split(input number)
FI                 Filter, removing zeros
             J:'+  Join on the + character

(A similar approach would be 19 bytes in Pip Classic: _FI(^a).RV0X,#aJ:'+.)

Canvas, 14 13 bytes
Ａ⁸Ｌ²－＾×？²｝］+＊

Try it here!

Clean, 73 bytes
import StdEnv,Text
$n=join"+"[rpad{c}(size n-p)'0'\\c<-:n&p<-[0..]|c>'0']

Try it online!
Defines the function $ :: String -> String taking a string and returning a string.

Japt, 13 bytes
Takes input as an array of digits.
í*¡ApYÃw)f q+

Try it

Explanation
í                 :Interleave
  ¡               :  Map input
   A              :    10
    p             :    To the power of
     Y            :    The current 0-based index
      Ã           :  End map
       w          :  Reverse
 *                :  Reduce each pair by multiplication
        )         :End interleaving
         f        :Filter (remove 0s)
           q+     :Join with "+"

Alternative
Takes input as an array of digit strings.
ËúTUÊ-EÃfn q+

Try it

Attache, 37 bytes
Join&"+"@{Id\`-&>Pairs[_'0]}@Suffixes

Try it online!
Pointfree version (41 bytes): Join&"+"##`\&:Id##`-&>Pairs@`'&0@Suffixes
Explanation
Join&"+"@{Id\`-&>Pairs[_'0]}@Suffixes      input e.g.: 1203
                             Suffixes      take the suffixes of the input digit
                                           e.g.: [1203, 203, 3, 3]
         {                 }@              apply the inner lambda to the suffixes:
                       _'0                   append `0`
                                             e.g.: [1203, 203, 3, 3, 0]
                 Pairs[   ]                  generate the pairs of integers of the above
                                             e.g.: [[1203, 203], [203, 3], [3, 3], [3, 0]]
             `-&>                            subtraction over each pair
                                             e.g.: [1000, 200, 0, 3]
          Id\                                keep only truthy (nonzero) elements
                                             e.g.: [1000, 200, 3]
Join&"+"@                                  join the result by `+`
                                           e.g.: "1000+200+3"

Powershell, 55 52 bytes
$i=$args.Count;($args|%{$_+'0'*--$i}|?{+$_})-join'+'

Script expects an array of strings, each string contains one digit. Test script:
$f = {

$i=$args.Count;($args|%{$_+'0'*--$i}|?{+$_})-join'+'

}

@(
    ,('10','1','0')
    ,('10+2','1','2')
    ,('9','9')
    ,('100+20+3','1','2','3')
    ,('100+1','1','0','1')
) | % {
    $e, $a = $_
    $r = &$f @a
    "$($e-eq$r): $(-join$a)=$r"
}

Output:
True: 10=10
True: 12=10+2
True: 9=9
True: 123=100+20+3
True: 101=100+1

C (gcc), 87 bytes
j;k;f(x){for(j=1;j<x;j*=10);for(;k=x*10/j*j/10%j,j/=10;)k&&printf("%d%c",k,j-1?43:10);}

Try it online!

Java 10, 82 78 bytes
n->f(n,1)Object f(int n,int m){return m<n?f(n-n%m,m*10)+(n%m>0?"+"+n%m:""):n;}

Port of Arnauld's JavaScript (ES6) answer.
-2 bytes thanks to @ceilingcat.
-2 bytes thanks to Arnauld.
Try it online.
Explanation:
n->                      // Method with int parameter & Object return-type
  f(n,1)                 //  Call the recursive method with `n` and 1

Object f(int n,int m){   // Recursive method with 2 int parameters & Object return-type
  return m<n?            //  If `m` is smaller than `n`:
          f(n-n%m,m*10)  //   Do a recursive call with `n-n%m` and `m` multiplied by 10
          +(n%m>0?       //   And if `n` is not divisible by `m`:
            "+"          //    Append a "+"
            +n%m         //    As well as `n%m`
           :             //   Else:
            "")          //    Append nothing more
         :               //  Else:
          n;}            //   Simply return the input `n`

I suppose this answer would also be a valid one for the original question. :) (Maybe with n%m assigned to a variable for readability.)

Nice! My original solution was 91 bytes.

@ceilingcat Actually, m<n should work.

Brainfuck, 147 bytes
>>+[[<]>+[>],]-[>+>+<<-----]>--->--------<<<[<]>---[[<+<+>>-]<[>+<-]>>.<<<[>>[>]>.<<[<]<-]>>[>]>>.<<<[<]>>>[<[-]>[<+>-]>]>[<+>-]>[<+>-]<<<<[<]>-]>.

Try it online!
(You will have to tick the box marked "!" and type your input after the "!" on the second line of the code otherwise it will continue asking for inputs forever.)
Its probably not going to be the shortest answer or golfed to the shortest it could be but it was pretty fun to try and do this in Brainfuck so I might as well post it.
As @JoKing pointed out, this program does not remove 0's. I will try and fix this but it might be quite hard.
Explanation:
>>+[[<]>+[>],]                            Takes inputs and records the amount of them
-[>+>+<<-----]>--->--------               Sets the next 2 cells to 48 (0) and 43 (plus)
<<<[<]>---                                Returns to the start and corrects the number of inputs
                                          Loop
[[<+<+>>-]<[>+<-]>>.                      Prints the first number
<<<[>>[>]>.<<[<]<-]                       Prints the correct number of 0's
>>[>]>>.                                  Prints plus
<<<[<]>                                   Returns to the first cell
>>[<[-]>[<+>-]>]>[<+>-]>[<+>-]<<<<[<]>-]  Removes the first number and shifts everything up by one to make the second number the first
                                          Loops until on last number
>.                                        Prints last number

Sorry, but this doesn't remove zeroes as specified. Try it online!

Thanks, I didn't notice that. I'll try and fix that. Whilst I am, I will edit my post

SNOBOL4 (CSNOBOL4), 134 133 129 bytes
	N =INPUT
	S =SIZE(N) - 1
V	N LEN(X) LEN(1) . V	:F(O)
	O =GT(V) O V DUPL(0,S - X) '+'
	X =X + 1	:(V)
O	O ARB . OUTPUT RPOS(1)
END

Try it online!
Saved a whole byte by doing string processing rather than arithmetic!

sed -E, 109 99 97 75 74 bytes
h;s:.:0:g;G
:l;s:.(.*)\n(.)(.*)\+?(.*):\1\n\3+\4\2\1:;tl
s:\+0+::g;s:..?::

Each line of the input is considered a separate number. Try it online.
Explanation:
h;                                           | copy the original string to the temporary buffer
  s:.:0:g;                                   | substitute all digits with zeroes
          G                                  | append the original string to the substituted one
                                             |
:l;                                          | main loop start
   s:.(.*)\n(.)(.*)\+?(.*):\1\n\3+\4\2\1:;   | cut the next digit from the number, append with zeroes and add to the back
                                          tl | loop if the substitution hasn`t converged yet
                                             |
s:\+0+::g;                                   | remove all zero terms
          s:..?::                            | remove \n and the first +, if any

…can be golfed futher, I presume.

Hello and welcome to PPCG. Your answer looks fine, though I do not understand why you added a BADC0FFEE test case. I think the challenge is only about decimal representations.

You don't need to handle 01010101010 or 000000, according to the challenge spec. Does that save any bytes?

@Dennis Most probably no, as leading zeroes and the ones in between behave the same, so I need to erase them anyway.

MathGolf, 12 11 10 bytes
hrzúm*ç'+u

Try it online!
Explanation
The first command is not needed as input can be given as a list of digits.
(▒           Convert to a list of digits)
 h           Get length of input list without popping
  r          Push range(a)
   z         Reverse sort
    ú        Map i -> 10**i for each element in list
     m*      Element-wise multiplication
       ç     Filter faulty items in list
        '+   Push "+"
          u  Join with separator

I might add a pairwise multiplication operator that is one byte, but that's not currently part of the language. Then I could remove one byte from this solution.

APL (Dyalog Unicode), 20 bytes
{⍵'+'⍺}/0~⍨(10×⊢)\∘⌽

Try it online!
Takes input as a vector of digits. Outputs with a space before and after each +, and includes a variable amount of leading spaces.
This is a train. It is divided into the following.
  ┌───┴───┐
  /     ┌─┼──┐
┌─┘     0 ⍨  ∘
{⍵'+'⍺} ┌─┘ ┌┴┐
        ~   \ ⌽
          ┌─┘
       ┌──┼─┐
       10 × ⊢

The first function is ⌽, this reverses the array, so 1 0 2 becomes 2 0 1.
Then we come into (10×⊢)\, which is applied to the reversed array. This part is inspired by ngn's answer to the Boustrophedonise challenge. Borrowing ngn's explanation, given a vector of digits A B C ..., applying (10×⊢)\ on this vector gives the following.
A (A (10×⊢) B) (A (10×⊢) (B (10×⊢) C)) ...
A ((10×⊢) B) ((10×⊢) (10×C)) ...
A (10×B) (10×10×C) ...

On 2 0 1, (10×⊢)\ gives 2 0 100.
Next comes 0~⍨. This removes all 0s from the array, giving 2 100.
Finally comes the +s. {⍵'+'⍺}/ is a reduction that starts from the right that concatenates the left arg with a +, followed by the right arg. Effectively, this reverses the array while inserting +s. This gives 100 '+' 2, which is displayed as 100 + 2.

Vyxal, 8 bytes
ẏṘ↵*ꜝ\+j

Takes input as a list of digits.
Try it online, or verify all test cases.
Explanation:
   *       # Multiply each digit in the input by the corresponding value in:
ẏ          # the range from 0 to the length of the input
 Ṙ         # reversed
  ↵        # with each value mapped to 10^n.
    ꜝ      # Remove falsey values.
     j     # Join on
       \+  # "+"

Wolfram Language (Mathematica), 58 bytes
StringRiffle[ToString/@(NumberExpand[#]/.(0->Nothing)),"+"]&

In Use:
In[101]:= StringRiffle[ToString /@ (NumberExpand[#] /. (0 -> Nothing)), "+"] &[101]
Out[101]= "100+1"

BASH, 86 83 bytes
Try it online!
for((t=$1;++m<${#1};t=10#$g)){
g=${t#?}
b+=${t/$g}${g//?/0}+;}
a=$b$t
echo ${a//+0}

Pip, 21 bytes
W+:axPB['+POa0Ma];@>x

Takes input as a command-line argument. Try it online!
Explanation
Partially inspired by nimi's Haskell answer.
                       x is empty string; a is 1st cmdline arg (implicit)
W                      While loop
 +:a                    Loop condition: a, after unary + is applied in-place
                         Unary + adds 0 to a number, with the side effect of converting it to
                         standard numerical form; in this case, that means eliminating leading zeros
                        Inside the loop, we know that a is nonzero and has no leading zeros
       [        ]       Construct a list containing the following items:
        '+               A + character
          POa            Pop the first character from a (leaving a one character shorter)
             0Ma         Map 0 to a, giving a list of 0's with the same length as a
                        E.g. if a was 123, the list is ["+" 1 [0 0]] and a becomes 23
    xPB                 Push this list to the back of x
                        Since x is a string, PB will cast the list to a string and append it to x
                        The default list -> string format is to concatenate all the items, so in
                        the above example, x will have "+100" appended
                 ;     Required for parsing
                  @>x  Take all but the first character of x and autoprint it

Here's a less creative map-and-filter approach, also 21 bytes:
_FI_*t**BMZaRV,#aJ:'+

Try it online!
I tried a few ways to golf this, but ran into parsing problems that forced me back up to 21. Quite possibly there's a shorter way to do it.

Python 3, 114 bytes
s,n=[],input()
[s.append(("+"+n[-i-1]+"0"*i)*(int(n[-i-1])>0))for i in range(len(n))]
print("".join(s[::-1])[1:])

Try it online!

Why do you use a list comprehension to simulate a for loop that fills a list? Anyhow, 66 bytes.

I think I planned on having it be on one line but then I changed my mind and didn't reflect that back into the design; now that you say this, I think I will go back and make this cleaner.

brainfuck, 116 bytes
--->-[<+>-----]>,[>,]<[<]>[<<[->+>-<<]>>[[>]>[<<[<]>-----.+++++[>]]<<[<]>[->+<<+>]>.,>[[-<+>]<[<]<.>>[>]>],+<<[<]]>]

Try it online!
Explanation:
--->-[<+>-----]     Push 48
Tape: 48 0'
>,[>,]<[<]          Get all inputted digits
Tape: 48 0' digits
>[                  Loop over each digit
  Tape: 48 0 d' igits
  <<[->+>-<<]       Subtract 48 from the digit
  Tape: 0' 48 d-48 igits
  >>[               If the digit is not a zero
     [>]>[          Check if the flag is set
        [<]>-----.  Subtract 5 from the 48 to print a plus
        +++++[>]    Restore the 48
     ]
     <[->+<<+>]     Restore the 48 and the first digit
     Tape: 48 0' d igits
     >.,            Print and remove the first digit
     Tape: 48 0 0' igits
     >[             For each of the remaining digits
        [-<+>]      Move it over one
        <[<]<.      Print a zero
        >>[>]>      Move to the next digit
     ]
     Tape: 48 0 digits? 0 0'
     ,+<<[<]        Set the plus flag
     Tape: 48 0' digits? 0 1
  ]
  Tape: 48 0' digits?
>]

MBASIC, 131 bytes
1 INPUT N$:N=VAL(N$):FOR P=LEN(N$)-1 TO 0 STEP -1:T=10^P:X=INT(N/T):G=X*T
2 IF G>0 THEN PRINT G;:N=N-G:IF N>0 THEN PRINT"+";
3 NEXT P

Input a number as a string, allowing us to walk it's length, subtracting power of 10 multiples as we go.
? 12
10 + 2

? 9
9

? 123
100 + 20 + 3

? 10
10

? 101
100 + 1

PHP, 89 bytes
<?for($i=0;$i<$l=strlen($a=$argv[1]);$i++)echo$a[$i]?($i?"+":"").$a[$i]*10**($l-$i-1):"";

Try it online!

Ruby, 55 bytes
->n{w=-1;(n.digits.map{|x|x*=10**w+=1}-[0]).reverse*?+}

Try it online!

Thunno 2, 9 bytes
Żre×0o'+j

Try it online!
Note: 0o could also be æ; or Dị.
Explanation
Żre×0o'+j  '# Implicit input
Żr          # Push (length..0]
  e         # Ten power of each
   ×        # Multiply with input
    0o      # Remove zeros
    æ;      # OR truthy items only
    Dị      # OR filter by itself
      '+j  '# Join by "+"
            # Implicit output

Ruby -pl, 47 bytes
gsub(/.(?=.)/){$&+?0*$'.size+?+}
gsub /\+0+/,''

Attempt This Online!


text:
Traceless Busy Beaver
All those busy beavers made quite a mess. They wrote all over the tape. At this rate, our neighbour will stop lending us unbounded tapes.
We need a new way to play the busy beaver game, one that doesn't ruin every tape we use.
The Rules
Brainfuck only. Memory tape is unbounded both ways. Input instruction will always read \$0\$, so it can be used to clear a value.
50 bytes source limit.
At the end of execution, memory must be all \$0\$s.
Score is distance between the memory pointer's starting location and final location - if it takes \$n\$ move instructions to go between them, your score is \$n\$. Higher is better. Provide an exact value if you can, otherwise provide an estimate.
Example
32 bytes, \$2^{255}-1\$
-[-[[>]+>+[<]>-[[>]<+<+[<]>-]]>]

Explanation
-                                Initialize the list to [255].
 [                             ] Repeat as long as the list is not empty.
 [-                            ] Decrement the left end. We need to shrink the numbers so it ends eventually.
 [ [                         ] ] Skip if 0 already.
 [ [[>]                      ] ] Move to the cell past the right end.
 [ [   +                     ] ] Make this cell 1.
 [ [    >                    ] ] Go right again.
 [ [     +                   ] ] Make this cell 1. We've now appended [1, 1].
 [ [      [<]>               ] ] Go back to the first nonzero cell on the left.
 [ [          -              ] ] And decrement it.
 [ [           [            ]] ] We will need to transfer the rest of the number from the left to the right, so keep looping.
 [ [           [[>]<        ]] ] Go to the last nonzero cell on the right.
 [ [           [    +<+     ]] ] Increment this and the one on the left. These are the cells we appended earlier. We transfer to them.
 [ [           [       [<]> ]] ] Go back to the first nonzero cell on the left, which we are transferring from.
 [ [           [           -]] ] Decrement here on the left to balance out the incrementing on the right.
 [                            >] We end the iteration on a now empty cell. Move right, the new left end is there.

We begin with the list \$[255]\$. At each iteration, we consume the value \$n\$ on the left of the list, and if \$n>1\$, we append \$[n-1, n-1]\$ to the right. The numbers appended \$(n-1)\$ are lower than the original \$(n)\$, so they will get smaller until they are \$1\$, at which point they are consumed without expanding. Thus, the process ends eventually, with all \$0\$s in memory. However, at each step, the number of copies of the number doubles. The score of this program initialized with the list \$[n]\$ is \$2^n-1\$.
This example is meant to show some of the techniques used in creating a submission. It's not competitive for its size.

Is there any reason for the "50 bytes source limit."? It seems arbitrary

@Okx do you have an alternative scoring suggestion? Removing the byte limit would seem to lead to unbounded length code in order to be competitive...

@trichoplax oh, I might not have read the challenge correctly, sorry.

@Okx no problem - that wasn't intended as a criticism. If there's another way to score this that allows arbitrary code length, now is the time to find it before answers come in. I'm going to retag this as currently the code golf tag is misleading

There has to be some limit, since more bytes lets you define a faster growing function. There's no reason in particular for 50, it looks high enough for some decent growth (definitely better than my example's exponential) and creative solutions but still too small for Beklemishev's worm or other extremely fast growth. // Thanks for fixing my tags by the way, I rushed a bit getting this out.

Just for background: We try to avoid minimum scores for code golf, but this challenge is not code golf, and the number of bytes is not the score, so I see absolutely no problem with there being a 50 byte limit in this case.

Info: I think I can "trivially port" this answer from other challenge and get similar score.

I tried to port my answer from Largest number printable, but I can only get it down to 62 bytes :(

Sure, you can adapt a regular busy beaver. But you will lose some efficiency that way, it's like two separate programs, one that makes a mess and another that cleans it up. The score number may be similar but it'll be less competitive here. You can get more efficiency and a better score if you design something that cleans up after itself.

Note that the number of "states" is very limited, only 50. So it would be beneficial to keep some data on the tape itself, then clear it later.

@EPICI My previous busy beaver was already traceless, which is why I was trying to adapt it.

Score: \$ A(255, 2) - 1 = (2 \uparrow^{253} 5) - 4 \$
+<+<<++>-[-[<+>>[-<[->+<]+>>]+<-]>[>]+[<]+<]>[->]

\$ A \$ here is the Péter-Ackermann formulation of the Ackermann function, while the other score expression uses Knuth up-arrow notation. The 35-byte main loop [-[<+>>[-<[->+<]+>>]+<-]>[>]+[<]+<] can be used to compute \$ A(m,n) \$ by placing on the tape the values 1 - m, m, 1 <n times> and entering the loop with the pointer on the m cell. After the loop terminates, the nonzero tape contents are \$ A(m,n) \$ ones starting immediately to the right of the pointer.
I used the following Python program for modeling the behavior of the program:
def a(M, N):
    assert M > 0
    m = [-M + 1, M]
    n = N
    while m[-1]:
        while m[-1] > 1:
            m[-1] -= 1
            m[-2] += 1
            while n:
                m.insert(-1, 1)
                n -= 1
            n = 1
        n += 2
        m.pop()
    return n

You could increase your score by adding a trailing >.

wow, very impressive

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Crop ASCII Art Challenge
ASCII art is fun. Modern text editors are very good at manipulating text. Are modern programming languages up to the task?
One common task in ASCII art manipulation is to crop text to a rectangle between two characters. This is the task you must implement in this challenge.
Details
Your program will take 3 inputs:

the first is the 'start' character of the block - marking the top-left corner
the second is the 'end' character of the block - marking the bottom-right corner
the third is some form of multiline text, either a string, or list of strings, or filename, or whatever

The result will be multiline text (again, in any of the above formats) cropped to the rectangle between the given inputs. Note that the first two inputs may not be unique.
Edge cases
Boxes must always have volume at least 2. Thus these:
()     (
       )

are boxes but these:
)(     )      (
       (     )

are not (with start=( and end=)).
The input will only contain one box. Thus the start and end characters must only occur once, unless they are the same character in which case they must occur exactly twice.
Additionally each line in the input must be at least as long as the distance from the start of a line to the right edge of the box in the input.
Your program does not need to handle invalid inputs; they may result in undefined behavior.
Rules
Typical code-golf rules apply. Shortest code wins.
Examples
Sunny-day: start: ( end: ) input:
This is some text
. (but this text
  is in a box  ).
So only it is important.

Output:
(but this text
is in a box  )

Note the stripping of horizontal space as well. ASCII art crops are 2d.
Rainy-day: start: ( end: ) input:
This is some text (
But is that even  )
really a box?

Output:
(
)

Same start/end: start: / end: / input:
Oh, I get how this could be useful
 /----------------------------\
 | All this text is in a box! |
 \----------------------------/

Output:
/----------------------------\
| All this text is in a box! |
\----------------------------/

Invalid input: start: ( end: ) input:
Boxes are rectangular ( so this has
0 volume ) which is illegal.

Invalid input 2: start: ( end: ) input:
(The lines must already be square
so this line that is too short
relative to this end, is illegal)

What about a valid box with a line outside that is shorter than the box?

clarified, also invalid input

what should be the outcome in case of an invalid input? or are they mentioned so they won't have to be taken care of?

The outcome is much like undefined behaviour in C, don't worry about it, anything goes.

This is a nasty little challenge: nice job!

Is only horizontal whitespace trimmed? Or any characters outside the "box"? For example, if the "box" is in the middle of a "field" of dots (like ../---\.., ..|foo|.., ..\---/.. with / and / as your start and end), what is the expected output?

Edited for clarity. Every character outside the "box" is trimmed.

Vim, 16, 12 bytes/keystrokes
#<C-v>Nj*yggVGp

Try it online! in the V interpreter

Modern text editors are very good at manipulating text. Are modern programming languages up to the task?

I bet old text editors are even better! :D
Even though it doesn't necessarily have to, this answer does work with both of the given "invalid" inputs, outputting
 rectangular (
) which is ill

and
(The lines must already be square
so this line that is too short
relative to this end, is illegal)

Explanation:
#               " Move backward to the previous occurrence of the word (or in this case, character) under the cursor
 <C-v>          " Start a visual block selection
      N         " Go to the next occurrence of the last searched term (guaranteed to be line 1)
       j        " Move down a line
        *       " Move forward to the next occurrence of the character under the cursor
         y      " Yank (copy) the whole visually selected block
          gg    " Go to line 1
            VG  " Select every line
              p " And paste what we last copied over it, deleting the whole buffer and replacing it with the block

Incidentally this is exactly the use-case I was doing to prompt me to write this challenge. I had my q macro as /\/<cr><c-v>nygv$o0dp or something like that for far too long :)

Yeah, rectangular is the illest!

Jelly, 13 bytes
=€SŒṪr/,þ/Zœị

A dyadic link accepting a list of start and end characters on the left and a list of lines (as lists of characters) on the right which yields a list of lines (as lists of characters).
Try it online! (full program - if inputs are valid Python they will require Python-string-quoting.)
How?
=€SŒṪr/,þ/Zœị - Link: [start, stop], lines
 €            - for each (of [start, stop]):
=             -   equals? (vectorises across the lines)
  S           - sum (vectorises)
   ŒṪ         - multi-dimensional truthy (i.e. non-zero) indices
      /       - reduce by:
     r        -   inclusive range (vectorises)
         /    - reduce by:
        þ     -    outer product with:
       ,      -       pair
          Z   - transpose
           œị - multi-dimensional index-into (the lines)

As an example, with left = ['a', 'b'] and right (as a list of lists of characters - the lines):
--------
--a+++--
--++++--
--+++b--
--------

=€ yields a list of two lists of lists (the first performs 'a'=, the second 'b'=):
00000000         00000000
00100000         00000000
00000000    ,    00000000
00000000         00000100
00000000         00000000

summing this yields a single list of lists (summing element-wise):
00000000
00100000
00000000
00000100
00000000

ŒṪ then gives us the (1-indexed) multi-dimensional indices of the non-zeros, [[2,3],[4,6]] - i.e. [[top,left],[bottom,right]].
r/ then performs [2,3]r[4,6] which, since r vectorises, is like [2r4, 3r6], evaluating to [[2,3,4],[3,4,5,6]] - i.e. [rows,columns].
,þ/ then performs [2,3,4],þ[3,4,5,6] where þ is an outer-poduct instruction and , is pair. This yields all the [row,column] values by column, in this case:
[[[2,3],[3,3],[4,3]],
 [[2,4],[3,4],[4,4]],
 [[2,5],[3,5],[4,5]],
 [[2,6],[3,6],[4,6]]]

We want these by row, so Z is used to transpose this to:
[[[2,3],[2,4],[2,5],[2,6]],
 [[3,3],[3,4],[3,5],[3,6]],
 [[4,3],[4,4],[4,5],[4,6]]]

Finally œị indexes back into the input lines:
a+++
++++
+++b

It's worth noting that when both bounding characters are the same =€ identifies both twice but SŒṪ ends up doing the right thing, since 2 is truthy, e.g. with ['a','a']:
--------         00000000   00000000        00000000
--a+++--         00100000   00100000        00200000
--++++--  =€ ->  00000000 , 00000000  S ->  00000000  ŒṪ ->  [[2,3],[4,6]]
--+++a--         00000100   00000100        00000020
--------         00000000   00000000        00000000

... I read the explanation, but I still don't understand it. o_o Could you add a worked example, perhaps?

Incentivisation: I'll accept your answer if it is fully explained. :)

@DLosc - done, hope it helps.

@LambdaBeta - the V answer is shorter.

...err the Vim answer even.

APL (Dyalog), 38 30 bytes
4 bytes saved thanks to @EriktheOutgolfer
(1-⍨w-⍨⊃⍸⎕=s)↑(w←∊⊃⌽⍸⎕=s)↑s←↑⎕

Try it online!

too complicated. you could accept a matrix instead of vector of vectors, find the two positions with ⍸matrix∊separators, and do take/drop with them

(⍸a=⎕)↓(1+⍸a=⎕)↑a←⎕ with ⎕io←0

@ngn OP said number of characters differs between lines so I assumed input should be vector before processing. Even so, I need the selection parts (first and rotate) in case the delimiter shows a few times (see third test case), but I guess the drop does cut a few bytes, so thanks! I'll update once I get to PC

oops... I forgot about the third case, sorry. Then maybe: ⊃{⌽⊖⍵↓⍨⊃⍸⍺=⍵}/⎕⎕⎕ (sic, with 3 trailing quads) which is even shorter. Or ... ⎕⎕(↑⎕) if a pre-mixed matrix is not allowed.

Jelly, 14 bytes
œẹⱮẎQr/Ṛṭþ/œị⁸

Try it online!

I tried running your code on some of the other examples, but only got a crash. Is that a bug, or am I just doing something wrong?

@IlmariKaronen You haven't quoted the second argument properly (didn't mention that in the post); wrap it in single or double quotes. The way you've invoked it, the second argument is an empty (Python) tuple (()), not '()'. If it's parse-able, it needs to be quoted, however, my // doesn't need to be quoted (integer division operator without operands? hm...).

@IlmariKaronen I "think" that () is just being interpreted by Jelly as some kind of special character. Most pairs of characters I try work. I'd love to hear what people more familiar with Jelly think. EDIT: ninja-ed by erik the outgolfer

OK, yeah, that works.

Python 2, 130 bytes
def f(s,e,t):
 a=[(i,l.find(c))for i,l in enumerate(t)for c in s+e if c in l];r,c,R,C=a[0]+a[-1]
 for l in t[r:R+1]:print l[c:C+1]

Try it online!

Canvas, 37 bytes
｛³⁴⁰；ｘ≡‽┐
Ｘ⁸）Ｊ╵⁶；┤ω┤⁵Ｘ⁶⁸⁰Ｋ├；┐┤└∔┘┘∔；＠

Try it here!
36 bytes for getting the coordinates of the characters (and converting them to x,y,w,h because that's what ＠ takes) and 1 byte for getting the subsection.. There must be a better approach

JavaScript (ES6), 98 bytes
Takes input as two integers and an array of strings. Returns an array of strings.
(x,y,a,X=Y=0)=>a.filter(s=>!Y&&(Y=-~s.indexOf(y,X?X-1:X=-~s.indexOf(x)),X)).map(s=>s.slice(X-1,Y))

Try it online!
Commented
( x,                          // x = start character
  y,                          // y = end character
  a,                          // a[] = array of strings
  X =                         // X = position of x, plus 1
  Y = 0                       // Y = position of y, plus 1
) =>                          //
  a.filter(s =>               // for each string s in a[]:
    !Y &&                     //   reject this string if Y is non-zero
    (                         //   otherwise, use the 2nd condition:
      Y = -~s.indexOf(        //     update Y:
        y,                    //       by looking for y in s
        X ?                   //       if X is non-zero:
          X - 1               //         start the search at X - 1
        :                     //       else:
          X = -~s.indexOf(x)  //         update X and start the search at X
      ),                      //     end of Y update
      X                       //     keep this string if X is non-zero
    )                         //   end of 2nd condition
  )                           // end of filter()
  .map(s =>                   // for each remaining string s:
    s.slice(X - 1, Y)         //   remove left and right characters outside the box
  )                           // end of map()

filter and map?! Would building a new array with reduce or a recursive solution not work out shorter? On me phone, down the pub or  I'd give it a go myself.

@Shaggy There's probably a shorter way indeed, but I think that this method is doomed to use 2 passes: the 2nd loop cannot start before the 1st one terminates and both X and Y are known for sure.

Java 10, 204 bytes
(s,e,a)->{int b=-1,i=0;for(;i<a.length;i++)a[i]=(b=b<0?a[i].indexOf(s):b)<0|a[i].length()<b?"":a[i].substring(b);for(b=-1;i-->0;)a[i]=(b=b<0?a[i].indexOf(e):b)<0|a[i].length()<b?"":a[i].substring(0,b+1);}

Modifies the input-array instead of returning a new one to save bytes. This does mean that removed lines become "" instead, though. If this is not allowed I will change it.
Try it online.
Explanation:
(s,e,a)->{                 // Method with 2 Strings & String-array parameters and no return
  int b=-1,                //  Boundaries-integer, starting at -1
  i=0;for(;i<a.length;i++) //  Loop `i` in the range [0, amountOfLines)
    a[i]=                  //   Change the `i`th line in the array to:
      (b=b<0?              //    If `b` is -1:
          a[i].indexOf(s)  //     Set `b` to the index of `s` in the current line
                           //     (which is still -1 if it's not found)
         :                 //    Else (starting index already found)
          b                //     Leave `b` unchanged
      )<0                  //    Then, if `b` is -1,
         |a[i].length()<b? //    or the current line-length is too short:
       ""                  //     Remove the current line
      :                    //    Else:
       a[i].substring(b);  //     Shorten the line by removing every character before `b`
  for(b=-1;                //  Reset `b` to -1
      i-->0;)              //  Loop `i` in the range (amountOfLines, 0]
    a[i]=                  //  Change the `i`th line in the array to:
       (b=b<0?a[i].indexOf(e):b)<0|a[i].length()<b?"":
                           //   Similar as above (with end `e` instead of start `s`),
         a[i].substring(0,b+1);}
                           //   except we remove every character after `b` this time

For example:
With the inputs start = "(", end = ")" and lines =
["This is some text",
 ". (but this text",
 "  is in a box  ).",
 "So only it is important."]

the first loop will crop it at the top and left, changing it to this:
["",
 "(but this text",
 "is in a box  ).",
 " only it is important."]

the second loop will crop it at the bottom and right, changing it to this:
["",
 "(but this text",
 "is in a box  )",
 ""]

Retina 0.8.2, 110 bytes
^((.)¶.)(.*¶)+(.*\2)
$1¶$4
^(.)(¶.¶\1)
$2
}s`(?<=^.¶.+)¶.
¶
s`^¶(.)¶(.*\1).*
$2
+m`^((.)+).¶((?<-2>.)+)$
$1¶$3

Try it online! Explanation:
^((.)¶.)(.*¶)+(.*\2)
$1¶$4

Delete the input lines preceding the first line of the box.
^(.)(¶.¶\1)
$2

If the start character is in the left column of the input, delete it.
}s`(?<=^.¶.+)¶.
¶

If the start character hasn't been deleted yet, shift all the input columns left by one and repeat from the beginning.
s`^¶(.)¶(.*\1).*
$2

Delete the end character and everything in the input after the end character.
+m`^((.)+).¶((?<-2>.)+)$
$1¶$3

Truncate all the lines to the length of the next line. This works by counting all but one character on each line, then attempting to match up to that many characters on the next line; if this succeeds then the second line was shorter, so the last character is deleted and the loop repeats.

C (gcc), 237 bytes
f(c,r,o,p)char*p,*c;{char*_=strchr(p,r),*a,b;*_=0;a=strrchr(p,10);a=(a?a:p);*_=r;r=_-a;p=a;_=strrchr(p,o);*_=0;a=strrchr(p,10);a=(a?a:p);*_=o;o=_-a+1;_[1]=0;for(_=p;_;_=strchr(_+1,10)){b=_[o];_[o]=0;strcat(c,_+r);strcat(c,"\n");_[o]=b;}}

Try it online!
I'm 99% sure this can be shortened using some kind of helper function to find horizontal index of and pointer to a character, as it is repeated twice. Alas I couldn't find a short enough way to do it, I may try again later if I find the time.
Description
f(c,r,o,p)char*p,*c;{
    char*_=strchr(p,r),*a,b;         // find opening char (and declare vars)
    *_=0;a=strrchr(p,10);            // find \n before it
    a=(a?a:p);                       // deal with single line inputs
    *_=r;r=_-a;                      // save left margin width in r
    p=a;                             // crop everything before opening line

    _=strchr(p,o);                   // find closing char
    *_=0;a=strrchr(p,10);            // find \n before it
    a=(a?a:p);                       // deal with single line inputs
    *_=o;o=_-a+1;                    // save width in o
    _[1]=0;                          // crop everything after closing char
    for(_=p;_;_=strchr(_+1,10)){       // for each line
        b=_[o];_[o]=0;
        strcat(c,_+r);
        strcat(c,"\n");
        _[o]=b;
    }
}

Even better: 219 bytes

Building on @Zachary 209 bytes

Stax, 15 bytes
╛↨½╝v∞░W╧)╗Ö≈☼k

Run and debug it
It takes the set of box delimiter characters (1 or 2) on the first line of input.  The rest of the lines are the input body.
Unpacked, ungolfed, and commented, it looks like this.
            first line of input is the delimiter characters
dL          discard the first line of input and listify the rest into an array
{           begin block for iteration
  Mr        rotate matrix 90 degrees
  {         begin block for while loop
    ch      copy first row of block
    y|&C    if it insersects with the first line of input, break iteration
    D       drop the first line
  W         do-while loop until break
}4*         execute block 4 times
m           display result lines

Run this one

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Everyone Ought to Have a Friend
An isolated character is a character (other than a newline) that doesn't have an adjacent character of the same type.  Adjacent characters can be to the left, the right above or below, but not diagonals.  For example in the following text H is isolated:
Ybb
YH%
%%%%

All the other characters are not isolated because each of them has at least one other character of the same type adjacent.
Your task is to write a program that takes a string as input and determines the number of isolated characters.
Scoring
You answer will be scored by two metrics.  The first is the number of isolated characters in your program.  You should aim to minimize this.  The second will be the number of bytes in your program.  You should minimize this as well.  Program size will act as a tie breaker for the first criterion.
Additional Rules

You should support input on the printable ascii range plus any characters you use in your program.
You may consider a line break to either be a newline character or a newline followed by a line feed.
You may take input in any reasonable format.  This includes a list of lines.

Test Cases
Ybb
YH%
%%%%

\$1\$

Aaaab
uuu
yyybbb

\$2\$

A

\$1\$

qqWWaaww

\$0\$

Is an empty string valid input and if so would it score 0? Also how flexible is input type? List of lines fine?

Can newlines be isolated?

@DimChtz Because it has a Y below it.

@JoKing No it cannot.

What do you mean by type? Is it corresponding to the character's codepoint?

@AlexRacer Yes type is character's codepoint.

The 2nd rule suggests that the input cannot be taken as an array of lines. Or am I misinterpreting it?

The first metric can be circumvented in any programming language and every answer has a 0 score now.

@GB Indeed. I guess it's not too late for turning it into a restricted-source challenge instead and disallow isolated characters altogether.

Can input contain spaces?

@Arnauld Why would I make that change?  IIf GB is right that every language can score 0, it wouldn't even change the challenge.

@Adám Spaces are printable ASCII.

@Arnauld Input can be taken in any standard way.  I believe that list of lines is covered by this.  Luis Mendo seems to have taken this to be the case.

An interesting variation on this puzzle might be to make it a "toroidal" board (top wraps to bottom and left wraps to right).

Regarding my comment about turning this into restricted-source: this is just a possible simplification of the scoring system, as the first criterion is unlikely to make any difference. But the challenge is, of course, perfectly fine as it stands.

@GB  Could a c++ program get 0 as a score?  I guess it could using the Javascript answer's trick.

Python 2, 0 (350 344 314 309 301 298 291 bytes)
def f(tt):11
def f(tt):
 tt=tt.split('\n')
 r =0#.split('\n')
#r  0#
#for
 for  ii,ll in enumerate(tt):
  for jj,cc in enumerate(ll):
##for+=1-(
    r+=1-(cc in ll[(jj or 2)-1:jj+2:2]    +''.join(ll[jj:
 jj+1]for ll in tt[(ii or 2)-1:ii+2:2]))##+''.join(ll[jj:
#  +1]for
#print r
 print r

Try it online!
-7 bytes, thanks to Jo King

291 bytes

Clean, 0 (439 ... 415 bytes)
-11 thanks to Ørjan Johansen
Finally a challenge where I can score 0 with Clean!
(and normally it's bad at source-layout challenges!)
//module
  module d
import StdEnv,ArgEnv,Data.List,Data.Maybe
import StdEnv,ArgEnv,Data.List,Data.Maybe
Start=sum[1\\i<-l&v<-[0..],_<-i&u<-[0..]|all((<>)(?u v))[?(u-1)v,?(u+1)v,?u(v-1),?u(v+1)]]
Start=sum[1\\i<-l&v<-[0..],_<-i&u<-[0..]|all((<>)(?u v))[?(u-1)v,?(u+1)v,?u(v-1),?u(v+1)]]
l=mklines[c\\c<-:getCommandLine.[1]]
l=mklines[c\\c<-:getCommandLine.[1]]
?x=mapMaybe(\k=k!?x)o(!?)l
?x=mapMaybe(\k=k!?x)o(!?)l

Try it online!
The TIO link uses module main due to the way Clean is implemented on TIO, but module d will work if you name the file d.icl instead of main.icl as TIO does.
One of the old lines explained (new version is the same thing in a different order):
Start                                       // entry point
 = let                                      // define locals
  l = mklines                               // `l` is argument split at newlines
   [c \\ c <-: getCommandLine.[1]];         // the second command-line arg turned into a [Char]
  ? x y                                     // function ? of coordinate (x,y)
   = mapMaybe                               // if the argument isn't Nothing
    (\k = k!?x)                             // try taking the `x`-th index
    (l!?y)                                  // of the `y`-th index of `l`
  in                                        // in the context of
   sum [                                    // the sum of
    1                                       // the integer one
    \\ i <- l & v <- [0..]                  // for every index in `l`
    , _ <- i & u <- [0..]                   // for every subindex in `l`
    | all (                                 // where all of the second argument
      (<>)(?u v)                            // doesn't equal the first argument
     ) [?(u-1)v, ?(u+1)v, ?u(v-1), ?u(v+1)] // over every adjacent element
   ]

Not using let saves 11 bytes.

@ØrjanJohansen Thanks! I also changed the module header since we have an adjacent d handy

JavaScript (ES6), 0 (154 bytes)
Saved 2 4 bytes thanks to @ØrjanJohansen
Takes input as an array of strings.
s  =>
s//=>(s,y,a
.map((s,y,a)=>[...s]
.map((c,x  )=>[...s]
&&//++c,x
 s[x+1]==c|
 s[x-1]==c|
(a[y-1]||0)[x]==c|
(a[y+1]||0)[x]==c||
  i++),i=0)
&&i//),i=

Try it online!

156 bytes

153

147

Jelly, 0 (41 27 25 bytes)
ŒĠạþ`€Ẏ§CẠ€S
ŒĠạþ`€Ẏ§CẠ€S

Try it online!
Takes input as list of lines. The first line in the code never does anything and is only there to minimize isolated characters.
ỴŒĠạþ`€Ẏ§1eⱮCS
Ỵ                 Split the text on newlines.
 ŒĠ               Group the multidimensional indices by their value.
      €           For each list of indices:
   ạ                Take the absolute difference...
    þ`              ...between each pair.
       Ẏ          Concatenate the lists of differences.
        §         Sum the x & y differences. This computes the Manhattan distance.
                  At this point we have a list for each character in the text of
                  Manhattan distances between it and it's identical characters.
         1eⱮ      Is there a 1 in each of the lists? None for isolated characters.
            C     Complement: 0 <-> 1.
             S    Sum. Counts the isolated characters

MATL, 0 (54 bytes)
TTTTf"Go@X!0JQJ&(d@_X!]***ggss
%%%%f"Go@X!0JQJ&(d@_X!]

Input is a cell array of strings, one for each line: {'line 1', 'line 2', 'and line 3'}.
Try it online! Or verify test cases and source code.

05AB1E, 0 (101 bytes)
žGçU|€SXζζD"εγεDgDisëXи]"©.V˜sø®.V€Sø˜‚øʒË}ʒXå≠}gq
žGçU|€SXζζD"εγεDgDisëXи]"©.V˜sø®.V€Sø˜‚øʒË}ʒXå≠}gq

Try it online.
This is one of the ugliest and longest 05AB1E programs I've ever written.. >.> This challenge is deceivingly hard in 05AB1E. I have no doubt in mind the byte-count can at least be halved or even three/four times as small by using a different approach (or even with a similar approach), but I currently don't see how. I'm just glad it's working right now.. If someone else posts a much shorter 05AB1E answer with some smart tricks I'll probably delete this answer out of shame... xD
Explanation:
žGç                # Character with unicode 32768 ('耀')
   U               # Pop and store it in variable `X`
                   # (This character is not part of the printable ASCII, nor of my 05AB1E code)
|                  # Take the multi-line input as list
                   #  i.e. "Ybb\nYH%\n%%%%" → ["Ybb","YH%","%%%%"]
 €S                # Convert each string to a list of characters
                   #  i.e. ["Ybb","YH%","%%%%"] → [["Y","b","b"],["Y","H","%"],["%","%","%","%"]]
   Xζζ             # Zip with character `X` as filler twice to make the lines of equal length
                   #  i.e. [["Y","b","b"],["Y","H","%"],["%","%","%","%"]]
                   #   → [["Y","b","b","耀"],["Y","H","%","耀"],["%","%","%","%"]]
      D            # Duplicate this list
"             "    # Create a string
               ©   # Which we store in the register (without popping)
                .V # And execute that string as 05AB1E code
 ε                 #  Map each inner list to:
  γ                #   Split in chunks of the same characters
                   #    i.e. [["Y","b","b"],["Y","H","%"],["%","%","%","%"]]
                   #     → [[["Y"],["b","b"]],[["Y"],["H"],["%"]],[["%","%","%","%"]]]
   ε               #   Map each of those to:
    D              #    Duplicate the current inner list
     gDi           #    If its length is exactly 1:
        s          #     Swap so the mapping keeps the duplicated single character (as list)
       ë           #    Else:
        Xи         #     Take character `X` repeated the length amount of times
                   #      i.e. ["%","%","%","%"] (length 4) → ["耀","耀","耀","耀"]
          ]        #  Close the if-else and both maps
           ˜       #  Flatten the list to a single list of characters
                   #   i.e. [[["Y"],["耀","耀"],["耀"]],[["Y"],["H"],["%"],["耀"]],[["耀","耀","耀","耀"]]]
                   #    → ["Y","耀","耀","耀","Y","H","%","耀","耀","耀","耀","耀"]
s                  # Swap so the duplicate list is at the top of the stack
 ø                 # Swap its rows and columns
                   #  i.e. [["Y","b","b","耀"],["Y","H","%","耀"],["%","%","%","%"]]
                   #   → [["Y","Y","%"],["b","H","%"],["b","%","%"],["耀","耀","%"]]
  ®.V              # Execute the same piece of code again that we've stored in the register
     €S            # Convert each to a list of characters
                   #  i.e. [[["耀","耀"],["%"]],[["b"],["H"],["%"]],[["b"],["耀","耀"]],[["耀","耀"],["%"]]]
                   #   → [["耀","耀","%"],["b","H","%"],["b","耀","耀"],["耀","耀","%"]]
       ø           # Swap its rows and columns back again
                   #  i.e. [["耀","b","b","耀"],["耀","H","耀","耀"],["%","%","耀","%"]]
        ˜          # Flatten this list as well
‚                  # Pair both lists together
                   #  i.e. [["Y","耀","耀","耀","Y","H","%","耀","耀","耀","耀","耀"],
                   #        ["耀","b","b","耀","耀","H","耀","耀","%","%","耀","%"]]
 ø                 # Swap its rows and columns to create pairs
                   #  i.e. [["Y","耀"],["耀","b"],["耀","b"],["耀","耀"],["Y","耀"],["H","H"],["%","耀"],["耀","耀"],["耀","%"],["耀","%"],["耀","耀"],["耀","%"]]
  ʒË}              # Filter out any inner lists where both characters are not equal
                   #  i.e. [["耀","耀"],["H","H"],["耀","耀"],["耀","耀"]]
     ʒXå≠}         # Filter out any inner lists that contain the character `X`
                   #  i.e. [["H","H"]]
g                  # Take the length as result
                   #  i.e. [["H","H"]] → 1
 q                 # Stop the program, making all other characters no-ops
                   # (and output the length above implicitly)

Python 3, 0 (323 bytes)
def f(s,e=enumerate):S={(x,y,c)for y,l in e(s.split("\n"))for x,c in e(l)};return-sum(~-any((x+u,y+v,c)in S for u,v in[(1,0),(~0,0),(0,~0),(0,1)])for x,y,c in S)
def f(s,e=enumerate):S={(x,y,c)for y,l in e(s.split("\n"))for x,c in e(l)};return-sum(~-any((x+u,y+v,c)in S for u,v in[(1,0),(~0,0),(0,~0),(0,1)])for x,y,c in S)

Try it online!

Ruby, score 0, 237 209 bytes
##->a{['',*a,''].each_cons(3).sum{|a,b,c|(0..b.size).count{|x|[[x>0&&b[x-1],a[x],b[x+1],c[x]]&[b[x
  ->a{['',*a,''].each_cons(3).sum{|a,b,c|(0..b.size).count{|x|[[x>0&&b[x-1],a[x],b[x+1],c[x]]&[b[x]]]==[[]]}}}

Try it online!

JavaScript (Node.js), 0 (279 bytes)
  s=>(b=s.map(Buffer)).map((x,i)=>x.filter((y,j)=>y-(g=(x,y)=>~~(b[x]&&b[x][y]))(i,j-1)&&y-g(i,j+1)&&y-g(i-1,j)&&y-g(i+1,j))).join``.length
//s=>(b=s.map(Buffer)).map((x,i)=>x.filter((y,j)=>y-(g=(x,y)=>~~(b[x]&&b[x][y]))(i,j-1)&&y-g(i,j+1)&&y-g(i-1,j)&&y-g(i+1,j))).join``.length

Try it online!
Receive input as array of lines.


text:
Half, Half Half, and, Half
Consider the following number sequence:

\$ 0, \frac{1}{2}, \frac{1}{4}, \frac{3}{4}, \frac{1}{8}, \frac{3}{8}, \frac{5}{8}, \frac{7}{8}, \frac{1}{16}, \frac{3}{16}, \frac{5}{16}, \frac{7}{16}, \frac{9}{16}, \frac{11}{16}, \frac{13}{16}, \frac{15}{16}, \frac{1}{32}, \frac{3}{32}, \frac{5}{32}, \dots \$

It enumerates all binary fractions in the unit interval \$ [0, 1) \$.
(To make this challenge easier, the first element is optional: You may skip it and consider the sequence starts with 1/2.)
Task
Write a program (complete program or a function) which...
Choose one of these behaviors:

Input n, output nth element of the sequence (0-indexed or 1-indexed);
Input n, output first n elements of the sequence;
Input nothing, output the infinite number sequence which you can take from one by one;

Rule

Your program should at least support first 1000 items;
You may choose to output decimals, or fractions (built-in, integer pair, strings) as you like;

Input / Output as binary digits is not allowed in this question;

This is code-golf, shortest codes win;
Standard loopholes disallowed.

Testcases
input output
1     1/2     0.5
2     1/4     0.25
3     3/4     0.75
4     1/8     0.125
10    5/16    0.3125
100   73/128  0.5703125
511   511/512 0.998046875
512   1/1024  0.0009765625

These examples are based on 0-indexed sequence with the leading 0 included. You would need to adjust the input for fitting your solution.
Read More

OEIS A006257

Josephus problem: \$ a_{2n} = 2a_n-1, a_{2n+1} = 2a_n+1 \$. (Formerly M2216)
0, 1, 1, 3, 1, 3, 5, 7, 1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, ...

OEIS A062383

\$ a_0 = 1 \$: for \$ n>0 \$, \$ a_n = 2^{\lfloor log_2n+1 \rfloor} \$ or \$ a_n = 2a_{\lfloor \frac{n}{2} \rfloor} \$.
1, 2, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, ...

A006257(n)/A062383(n) = (0, 0.1, 0.01, 0.11, 0.001, ...) enumerates all binary fractions in the unit interval [0, 1). - Fredrik Johansson, Aug 14 2006

"Input nothing, output the infinite number sequence one by one" Does it have to be one-by-one, or are we also allowed to output an infinite list (possible in Haskell, Elixir, 05AB1E, etc.)?

Can I output a list of strings? e.g. "1/2" "1/4" "1/8"...

@KevinCruijssen Infinite list is fine as long as you can take n elements from it later.

@Barranka I think it is acceptable. That is nothing different to print fractions to stdout.

When you say Input / Output as binary numbers is not allowed, you mean we can't write a function that returns a pair if ints, or a double in a language / implementation where double uses IEEE binary64 format?  I hope you don't mean was have to parse an ASCII string if we want to take an integer input?  Normal integer types are binary in languages like C.  Or do you mean the input/output can't be an array or string of integer or ASCII zeros/ones?

@PeterCordes I mean you cannot return / print a string with 0s and 1s. Should I edit it to make it clear? So, how should I describe this?

I'd say "input/output can't be a string or list of base-2 digits.  A single binary integer or float is ok".  I think that should be clear to people who are used to the common code-golf terminology of "convert to binary" meaning to turn an integer into a list of binary digits, and also clear to people who use low-level languages like C or assembly.  It's a bit awkward; I feel like there should be a better way to phrase it, but that's the best I've got.  (The first sentence is perfectly clear, I think, but maybe not to everyone.  The 2nd sentence is just clarification.)

Haskell, 25 bytes
pred.until(<2)(/2).(+0.5)

Try it online!
Outputs decimals, one-indexed without the initial zero term.
Adds 0.5 to the input, then halves until the results is below 2, then subtracts 1. Using a pointfree expression saves 1 bytes over
f n=until(<2)(/2)(n+0.5)-1

Java 10, 68 64 bytes
First try at code golf!
Option 1: find the n-th element (1-indexed)
-4 bytes thanks to @Kevin Cruijssen
n->{int x=0;for(;n>>++x!=1;);return((~(1<<x)&n)*2.+1)/(1<<x+1);}

This is an anonymous method that finds the n-th term by removing the most significant bit from n, doubling it and adding one, then dividing by the next highest power of 2.
Try it online!
Code walkthrough:
n->{                      // builds anonymous function with input n
int x=0;                  // stores floor of log(n) (base 2) for most significant digit
for(;n>>++x!=1;);         // calculates floor of log(n) by counting right shifts until 1
return((~(1<<x)&n)        // removes most significant digit of n
*2.+1)                     // multiplies 2 and adds 1 to get the odd numerator
/(1<<x+1);}               // divides by the next highest power of 2 and returns`

Will edit if it's necessary to print the final value instead of returning it.

Welcome to PPCG, good to have you with us :)

Hi, welcome to PPCG! Great first answer, +1 from me. Currently it's the same byte-count as my Java answer, but you can still golf some parts of your answer to make it shorter than mine: The {} after the loop can be a ; instead; you can remove the space after the return; 2.0 can be 2.; And changing the n>>x!=1;x++, 1<<x, and 1<<x+1 to n>>x++!=1;, 1<<x-1, 1<<x respectively also saves a byte. Try it online: 64 bytes. Enjoy your stay!

Oh, and if you haven't seen it yet: Tips for golfing in Java and Tips for golfing in  are both pretty interesting to read through. :)

See my 30 bytes answer, originally based on yours but golfed and golfed and golfed.

MathGolf, 5 4 bytes
╫\╨]

Try it online!
How it would look like with the operator working correctly
╫\)╨]   (")" adds 1 to TOS, making rounding behave as expected)

Try it online!
Explanation
╫     Left-rotate all bits in input
 \    Swap top two elements on stack, pushing the input to the top
  ╨   Round up to nearest power of 2
   ]  Wrap in array (just for pretty printing)

I took my inspiration from this question to solve the problem, my "own" solution was around 10-12 bytes I think.
I had intended for the round up to closest power of 2 to return the number itself if it was a number of two, but due to a mistake it rounds to the next power of two (e.g. 4 -> 8 instead of 4 -> 4). This will have to be fixed later, but now it saves me one byte.

I don't know MathGolf but if the ] serves no other purpose than formatting the output, I'd say you don't need to include it in your byte count.

I was unsure about it. Since the stack is printed on output as a joined string, it outputs a stack with the numbers 1 and 2 as 12. If that still counts I'll remove a byte

I think you should leave it in. It sometimes saves a byte to output the stack as one string, sometimes it will cost you a byte.

@H.PWiz that was my original thinking, since it seems fair to use the strengths of your language. Some languages only print the top of the stack when finished, some print it as a list. Usually it's a 1 byte difference, but it's part of the challenge.

Java (JDK 10), 30 bytes
n->(n+.5)/n.highestOneBit(n)-1

Try it online!
Returns the nth item in the sequence.
This answer is originally a succession of golfs of TCFP's Java answer. In the end, the golfs didn't look like the original answer anymore (though the math used is the same) so I decided to post the golfs as a separate answer instead of simply commenting on the TCFP's answer. So if you like this answer, go upvote TCFP's answer as well! ;-)
Intermediate golfs were:
n->{int x=0;for(;n>>++x!=1;);return((~(1<<x)&n)*2.+1)/(1<<x+1);} // 64 bytes (TCFP's answer when I started golfing)
n->{int x=0;for(;n>>++x!=1;);x=1<<x;return((~x&n)*2.+1)/x/2;}    // 61 bytes
n->{int x=n.highestOneBit(n);return((~x&n)*2.+1)/x/2;}           // 54 bytes
n->{int x=n.highestOneBit(n);return((~x&n)+.5)/x;}               // 50 bytes
n->((n&~(n=n.highestOneBit(n)))+.5)/n                            // 37 bytes
n->(n-(n=n.highestOneBit(n))+.5)/n                               // 34 bytes
n->(n+.5)/n.highestOneBit(n)-1                                   // 30 bytes, current score

And I was sitting here thinking my answer was as short as I could make it, you come along and cut it by more than half! Amazing stuff, definitely deserves a +1 from me.

@TCFP It was an iterative process over the span of several hours. I actually posted each intermediate golfing as a comment to your answer, but deleted them as I found better golfs. Thanks for the praise ;-)

Java 10, 89 85 70 69 68 bytes
v->{for(float j,t=2;;t*=2)for(j=1;j<t;j+=2)System.out.println(j/t);}

Port of @Emigma's 05AB1E answer, so outputs decimals indefinitely as well.
-15 bytes thanks to @Arnauld.
Try it online.
Explanation:
v->{                      // Method with empty unused parameter and no return-type
  for(float j,t=2;;       //  Loop `t` from 2 upwards indefinitely,
                   t*=2)  //  doubling `t` after every iteration
    for(j=1;j<t;          //   Inner loop `j` in the range [1, `t`),
                j+=2)     //   in steps of 2 (so only the odd numbers)
      System.out.println( //    Print with trailing new-line:
        j/t);}            //     `j` divided by `t`

How often can I say that I half your byte count? Well, I think this is the first time ;-)

@OlivierGrégoire Dang, now that is an impressive Java answer. :) I saw your 37-byte version as comment on TCFP's answer, but you even stripped off more bytes. It looks so extremely simple now in your 30-byte version, but it's still ingenious how you've golfed it from the initial version. Well done!

Perl 6, 19 bytes
{($_+.5)/2**.msb-1}

Try it online!

Python 3, 33 bytes
lambda n:(8*n+4)/2**len(bin(n))-1

Try it online!
Outputs decimals, one-indexed without the initial zero term.

05AB1E, 11 8 bytes
Saved 3 bytes thanks to Kevin Cruijssen.
∞oDÅÉs/˜

Try it online!
Explanation
∞         # start an infinite list [1...
 o        # calculate 2**N
  D       # duplicate
   ÅÉ     # get a list of odd numbers up to 2**N
     s/   # divide each by 2**N
       ˜  # flatten

-1 byte by using ∞ (infinite list starting at 1): ∞oεDÅÉs/}˜

@KevinCruijssen: Cool! That's a command I hadn't seen before. Thanks :)

Ah, and nice way of saving two more bytes due to the implicit mapping.. Hadn't even thought about that, lol..

:O how is this possible.  You condensed the ~2 page question into 8 bytes.

I was thinking using the prime numbers and a list of [1,2,4,4,8,8,8,8,16,16,...,2**n] and prepending the correct indexed prime followed by a /... But that wasn't working so well. Well, but not 8-bytes well. Something like 9LoDÅP)ζ.

Or, more accurately, LoDÅPs/˜.

Jelly, 9 bytes
Bṙ1Ḅ,æċ2$

Try it online!

PowerShell, 40 bytes
for($i=2;;$i*=2){1..$i|?{$_%2}|%{$_/$i}}

Try it online!
Outputs the infinite sequence as decimal values. Given language limitations, will eventually run into precision problems, but easily handles the first 1000 entries.
Starts by setting $i=2, then enters a for loop. Each iteration, we construct a range from 1..$i and pull out the odd values with |?{$_%2}. Those are fed into their own inner loop, where we divide each to get the decimal |%{$_/$i}. Those are left on the pipeline and output when the pipeline is flushed after every for iteration. Each iteration we're simply incrementing $i by $i*=2 to get the next go-round.

Haskell, 35 32 bytes
Edit: -3 bytes thanks to @Delfad0r.
[(y,2^x)|x<-[1..],y<-[1,3..2^x]]

This is an infinite list of integer pairs.
Try it online!

Haskell, 40 bytes
s=(1,2):[(i*2+u,j*2)|(i,j)<-s,u<-[-1,1]]

Try it online!
Infinite sequence as pairs of integers (starting from (1,2)).
Quite a bit longer than @nimi's answer, but the approach is completely different, so I decided to post it anyway.
This solution is based on the following observation.
Consider the infinite sequence
$$
\left\{\frac{1}{2},\frac{1}{4},\frac{3}{4},\frac{1}{8},\frac{3}{8},\frac{5}{8},\frac{7}{8},\frac{1}{16},\frac{3}{16},\ldots\right\}
$$
and apply the following steps.

Replace every number \$\frac{i}{j}\$ in the sequence with the list \$\left\{\frac{2i-1}{2j},\frac{2i+1}{2j}\right\}\$:
$$
\left\{\left\{\frac{1}{4},\frac{3}{4}\right\},\left\{\frac{1}{8},\frac{3}{8}\right\},\left\{\frac{5}{8},\frac{7}{8}\right\},\left\{\frac{1}{16},\frac{3}{16}\right\},\ldots\right\}
$$
Join all the lists into a single sequence:
$$
\left\{\frac{1}{4},\frac{3}{4},\frac{1}{8},\frac{3}{8},\frac{5}{8},\frac{7}{8},\frac{1}{16},\frac{3}{16},\ldots\right\}
$$
Add \$\frac{1}{2}\$ at the beginning of the sequence:
$$
\left\{\frac{1}{2},\frac{1}{4},\frac{3}{4},\frac{1}{8},\frac{3}{8},\frac{5}{8},\frac{7}{8},\frac{1}{16},\frac{3}{16},\ldots\right\}
$$

Notice how you get back to the sequence you started with!
The solution exploits this fact (together with Haskell's laziness) to compute the sequence s.

R, 42 41 bytes
function(n)2*c(y<-2^(log2(n)%/%1),n-y+.5)

Try it online!
-1 byte thanks to Robin Ryder
Returns a pair Denominator,Numerator. Uses the formula
\$\begin{equation}N = 2\times\left(n-2^{\lfloor \log_2(n)\rfloor}\right)+1\end{equation}\$ from the Josephus sequence and \$\begin{equation}D = 2^{\lfloor \log_2(n)\rfloor+1}\end{equation}\$ from the other sequence. Happily we are able to re-use the denominator as the two formulas have quite a lot in common!

41 bytes by distributing the multiplication.

@RobinRyder thanks! Always nice to see an improvement to an old golf :-)

Python 2 -  68 66 bytes
-2 bytes thanks to Kevin
from math import*
def g(n):a=2**floor(log(n,2));print(n-a)*2+1,2*a

Try it Online!

You can golf 1 byte by changing return 2*(n-a) to return(n-a)*2. And you could save an additional byte by using Python 2 instead of 3, so return can be print (with parenthesis).

@KevinCruijssen For someone who doesn't use Python, you certainly are a better Python programmer than me.

Hehe. :D Simple things like this comes with experience I guess. I'm on this site for about two years now I think (EDIT: Since April 2016). I sometimes even suggests things to golf for answers that are written in languages I had never seen before.. Some basic things work in most languages. For example, last week I suggested a golf for a T-SQL answer, and I once suggested a golf in a Red answer. xD

44 bytes using len and bin instead of log.

@ovs 42 bytes.

@JonathanFrech I recommended lambda n:(n-~n)/2**len(bin(n)[2:])-1 (36 bytes) before, but deleted the comment, as the answer would converge to xnor's.

Python 3, 53 51 bytes

Saved two bytes thanks to mypetlion; reusing default parameters to reset  n.

def f(m=2,n=1):n<m and print(n/m)&f(m,2+n)or f(m+m)

Try it online!

Swap the parameters to save 2 bytes: def f(m=2,n=1):n<m and print(n/m)&f(m,n+2)or f(m+m)

@mypetlion Cool, thank you!

Racket, 92 91 bytes
(define(f k(m 2)(n 1))(if(> k 0)(if(=(+ n 1)m)(f(- k 1)(+ m m))(f(- k 1)m(+ n 2)))(/ n m)))

Try it online!

Saved a byte thanks to Giuseppe -- removing superfluous whitespace.

MATL, 8 bytes
BnWGEy-Q

Try it online!
Returns Numerator, then Denominator. Uses the same method as my R answer, although it's a bit more efficient.
Explanation, with input 5:
           # implicit input 5
B          # convert to array of bits
           # STACK: [[1 0 1]]
n          # length (place of Most Significant Bit)
           # STACK: [3]
W          # elementwise raise 2^x
           # STACK: [8]
G          # paste input
           # STACK: [8, 5]
E          # double
           # STACK: [8, 10]
y          # copy from below
           # STACK: [8, 10, 8]
-          # subtract
           # STACK: [8, 2]
Q          # increment
           # STACK: [8, 3]
           # implicit end of program, display stack contents

Factor, 52 bytes
{ 1/2 } [ dup stack. dup 1 v+n append 2 v/n t ] loop

Try it online!
Prints each fraction on its own line forever. Keeps track of the array of all terms with equal denominator.
{ 1/2 }         ! Push the initial array
[ ... t ] loop  ! Loop forever:
  dup stack.    !   Print all fractions separated by a newline
  dup 1 v+n     !   Copy and add 1 to all fractions
  append 2 v/n  !   Join and halve all fractions

C++, 97 75 71 bytes
-26 bytes thanks to tsh, ceilingcat, Zacharý
float f(int i){float d=2,n=1;while(--i)n=d-n==1?d*=2,1:n+2;return n/d;}

Testing code :
std::cout << "1\t:\t" << f(1) << '\n';
std::cout << "2\t:\t" << f(2) << '\n';
std::cout << "3\t:\t" << f(3) << '\n';
std::cout << "4\t:\t" << f(4) << '\n';
std::cout << "10\t:\t" << f(10) << '\n';
std::cout << "100\t:\t" << f(100) << '\n';
std::cout << "511\t:\t" << f(511) << '\n';
std::cout << "512\t:\t" << f(512) << '\n';

You may just omit if(!i)return 0; since 0 is not required in the challenge.

When trying to golf C-like language. You should avoid using while but try for. for(;exp;) is as same as while(exp) but you can write two more other statement into it. Prefer ?: instead of if else, which would be shorter in most cases.

I don't think you need the (...) around d-n-1.

Wolfram Language (Mathematica), 22 bytes
2^Mod[Log2[2#+1],1]-1&

Try it online!

Shakespeare Programming Language, 426 bytes
,.Ajax,.Ford,.Act I:.Scene I:.[Exeunt][Enter Ajax and Ford]Ajax:You be the sum ofyou a cat.Ford:You cat.Scene V:.Ford:Is twice you nicer I?If solet usScene X.You be twice you.Let usScene V.Scene X:.Ford:Remember twice you.You be the sum oftwice the remainder of the quotient betweenI you a cat.Open heart.You big big big big big cat.Speak thy.Recall.Open heart.You be twice the sum ofa cat a big big cat.Speak thy.Let usAct I.

Try it online!
Outputs the sequence infinitely as both numbers separated by a space, with each item being separated by a newline.

Love it.  Lol You be twice the sum of a cat

Actually, it's "twice the sum ofa cat a big big cat" (i.e. 10 for some reason).

Excel 48 28  Bytes
Saved 20 bytes (!) thanks to tsh
=(A1+0.5)/2^INT(LOG(A1,2))-1

=MOD(A1+0.5,2^(INT(LOG(A1,2))))/2^INT(LOG(A1,2))
Assumes value in A1, output is in decimal.
If you want the output to be in fraction, you can create a custom format for the output cell as "0/###0" and it will show it as fraction.
Explanation:
Difficult to explain, since there is a shortcut taken to get to this formula.
Basically the numerator is a bit shift left of the input, and the denominator is the next power of 2 higher than the number input.
I originally started with Excel built in functions for BITLSHIFT and BITRSHIFT, but they will shift the entire 48 bits which is not what you want.  The functions DEC2BIN (and BIN2DEC) have a limit of -512 to 511 (10 bits) so this wouldn't work.  Instead I had to rebuild the number with a modulus of the original number, then times two, then add 1 (since the left digit would always be 1 before a shift).
=MOD(A1                        Use MOD for finding what the right digits are
       +0.5                    this will later add the left "1" to the right digits
           ,2^INT(LOG(A1,2)))) Take Log base 2 number of digits on the right
                               this creates the numerator divided by 2 (explained later)
/ 2^INT(LOG(A1,2))             The denominator should be 2^ (Log2 + 1) but instead of
                               adding a 1 here, we cause the numerator to be divided by 2 instead
                               This gives us a fraction.  In the numerator, we also added .5
                               instead of 1 so that we wouldn't need to divide it in both the
                               numerator and denominator
Then tsh showed how I could take the int/log out of the mod and remove it from numerator/denominator.

Examples:

What about =(A1+0.5)/2^INT(LOG(A1,2))-1?

Python 2, 44 bytes
def f(n):m=2**len(bin(n))/4;return 2*n-m+1,m

Try it online!
Function returns a tuple of (numerator, denominator). An input of 0 is not handled (it was optional).

return 2*n-m+1,m can be print-~n+n-m,m to save 2 bytes.

Husk, 13 bytes
ṁz*İ1zR:1İ2İ½

Try it online!
Abuses the built in sequences to the fullest.
Outputs an infinite list.
Explanation
ṁz*İ1zR:1İ2İ½
           İ½ powers of ½
       :1İ2   powers of 2, with 1 prepended
     zR       zip replicate the second by the first
 z*           then zip multiply that with:
   İ1         odd numbers
ṁ             map to each of the power arrays, and concatenate into single list

Factor, 68 66 bytes
Saved 2 bytes thanks to @chunes
[ 1 2 [ 2dup / . [ 2 + ] dip 2dup > [ 2 * 1 swap ] when t ] loop ]

Try it online!
Outputs the sequence infinitely.
[
  1 2                    ! First numerator and denominator
  [                      ! Loop body
    2dup /               ! Divide to get next element of sequence
    .                    ! Print the element
    [ 2 + ] dip          ! Add 2 to the numerator
    2dup >               ! If numerator > denominator
    [
      2 *                ! Multiply denominator by 2
      1 swap             ! Set numerator to 1
    ]
    when                 ! Functions like an if statement
    t                    ! Push true on the stack so the loop doesn't stop
  ]
  loop                   ! Run while top of stack is true (which is forever)
]

when is shorter than [ ] if.

@chunes Sweet, thanks!

Ruby, 31 bytes
->x{(2r*x+1)/2**x.bit_length-1}

Try it online!

><>, 19 18 bytes
Using xnor's idea, fixed by Jo King, -1 byte by making better use of the mirrors and another -2 bytes by Jo King because the ! was superfluous and ; is not required.
2*1+\1-n
2:,2/?(

Try it online!

You should be checking if it is smaller than 2 first, otherwise the first element is -0.25. Fix for the same amount of bytes

Thanks! I also managed to remove another byte by reusing the mirrors.

Why did you invert the condition? 16 bytes

Didn't notice that it would continue the loop. Are we allowed to not properly finish?

Yeah, terminating with an error is fine as long as the OP doesn't specify otherwise

APL (Dyalog Unicode), 15 bytes
1-⍨.5∘+÷2*∘⌊2⍟⊢

Try it online!
Anonymous prefix lambda.
Thanks to Adám for 4 bytes and to Cows quack for 2 bytes.
How:
1-⍨.5∘+÷2*∘⌊2⍟⊢ ⍝ Anonymous lambda, argument ⍵ → 10
            2⍟⊢ ⍝ Log (⍟) of ⍵ in base 2. 2⍟10 → 3.32192809489...
           ⌊     ⍝ Floor. ⌊3.32192809489... → 3
        2*∘      ⍝ Take that power of 2. 2³ → 8
       ÷         ⍝ Use that as denominator
   .5∘+          ⍝ ⍵ + 0.5 → 10.5. Using that as numerator: 10.5÷8 → 1.3125
1-⍨              ⍝ Swap the arguments (⍨), then subtract. 1-⍨1.3125 → 1.3125-1 → 0.3125

C (gcc), 63 bytes
No input, prints infinite sequence:
f(i,j){for(i=1,j=2;;i+=2,i>j&&(j*=2,i=1))printf("%d/%d ",i,j);}

Try it online!

60 bytes.

Building on @JonathanFrech 59 bytes

JavaScript (ES6), 44 bytes
Returns the \$n\$-th term, 1-indexed.
f=(n,p=q=1)=>n?f(n-1,p<q-2?p+2:!!(q*=2)):p/q

Try it online!

Ruby, 42 bytes
1.step{|i|(1..x=2**i).step(2){|j|p [j,x]}}

Try it online!
Prints integer pairs infinitely, starting from 1/2.

JavaScript (Node.js), 30 bytes
f=(n,d=.5)=>d>n?n/d:f(n-d,d*2)

Try it online! 0-indexed. Started out as a port of my Batch answer but I was able to calculate in multiples of \$\frac{1}{2}\$ which saved several bytes.

Stax, 8 bytes
▀`Ö²╬─}t

Run and debug it
This program uses stax's rational type.  It takes a 1-based integer index as input, and produces that sequence element.
Unpacked, ungolfed, and commented, it looks like this.
Hc  double the input and copy it
:GY unset all but the highest bit, and store in register Y
-^  subtract (leaving all the other bits), then increment
yu* push the value in register Y, then multiply by its reciprocal

Run this one

C# (.NET Core), 69 bytes
a=>{int b=1,c=2;while(a-->1){b+=2;if(b>c){b=1;c*=2;}}return b+"/"+c;}

Try it online!
Ungolfed:
a=> {
    int b = 1, c = 2;   // initialize numerator (b) and denominator (c)
    while (a-- > 1)     // while a decrements to 1
    {
        b += 2;         // add 2 to b
        if (b > c)      // if b is greater than c:
        {
            b = 1;      // reset numerator to 1
            c *= 2;     // double denominator
        }
    }
    return b + "/" + c; // return fraction as string
}

x86 machine code, 36 bytes
00000000: 4389 de46 5653 6800 0000 00e8 fcff ffff  C..FVSh.........
00000010: 83c3 0239 f37e edd1 e631 db43 ebe6 2564  ...9.~...1.C..%d
00000020: 2f25 6420                                /%d

Prints the sequence infinitely.
The hexdump is unlinked, e.g. the address for printf is a placeholder.
Assembly:
section .text
	global func
	extern printf
func:
	inc ebx			;set numerator to 1
	mov esi, ebx
	inc esi			;set denominator to 2
	loop:
		push esi
		push ebx
		push fmt
		call printf
		add ebx, 2	;increment numerator by 2
		cmp ebx, esi
		jle loop	;if numerator<denominator (eg ebx/esi<1), repeat loop
		shl esi, 1	;double the denominator
		xor ebx, ebx
		inc ebx		;reset numerator to 1
		jmp loop
section .data
	fmt db '%d/%d '

Try it online!

Python 3, 71 bytes
n,d=0,1
for t in range(int(input())):
    n+=2
    if n>d:n=1;d*=2
print(n/d)

Index starts with 0 at 0.0 and 1 at 0.5 and so on.
Try it online!

Zephyr, 82 bytes
set d to 2
while 1=1
for n from 1 to d/2
print((2*n)-1)/d
next
set d to d*2
repeat

Try it online!
Iterate over denominators 2, 4, 8, 16, ... forever. For each d (e.g. 8), iterate n from 1 up to d/2 (e.g. 1, 2, 3, 4). The desired odd-number numerators are then 2*n-1. Zephyr's built-in rational numbers mean we just do the division and print the result.
(I really think more languages should have built-in rational numbers!)

Batch, 73 bytes
@set/an=%1*2,d=1
:l
@if %d% leq %1 set/an-=d,d*=2&goto l
@echo %n%/%d%

Outputs 0/1 for an input of 0. Explanation: n is the numerator and d is the denominator. d is doubled each time until it exceeds the input, and the previous value of d is subtracted from n as it goes. This is slightly golfier than calculating n=%1*2+1-d separately.

Appleseed, 76 bytes
(def s(lambda((d 2)(n 1))(if(> n d)(s(* d 2))(cons(list n d)(s d(+ n 2))))))

Defines a function s that, when called without arguments, returns an infinite list of (<numer> <denom>) pairs. Try it online!
Ungolfed
(def sequence
  (lambda ((denom 2) (numer 1))
    (if (less? denom numer)
      (sequence (* denom 2))
      (cons
        (list numer denom)
        (sequence denom (+ numer 2))))))

Same idea as Jonathan Frech's Python function (right down to the order of the default arguments being important), except here we cons each result onto the (infinite) recursive call instead of printing it.

Perl 5 -a, 53 bytes
map{say"$_/$.";--$F[0]||exit}grep$_%2,1..$.while$.*=2

Try it online!
1-indexed.  First element is 1/2.  Outputs the first n elements.

Perl 6, 38 bytes
(0,{(1,3...2**@_-1)X/2**@_}...*)>>.say

Try it online!
Outputs elements infinitely, starting from 0.
An infinite sequence itself ends up at 40 bytes
.5,{$/=.nude;($1-$0-1??$0+2!!.5)/$1}...*

Try it online!

APL(NARS), 30 chars, 60 bytes
{⍵=0:0⋄(1+2×⍵-2*k)÷2*1+k←⌊2⍟⍵}

test:
f←{⍵=0:0⋄(1+2×⍵-2*k)÷2*1+k←⌊2⍟⍵}
  f¨0 1 2 3 4 5 6 7 8
0 0.5 0.25 0.75 0.125 0.375 0.625 0.875 0.0625
  f¨511 512  10023
0.998046875 0.0009765625 0.2235717773

D, 66 bytes
T f(T)(T i){T d=2,n=1;while(--i)n=d-n==1?(d*=2)/d:n+2;return n/d;}

Try it online!
Port of @HatsuPointerKun's C++ answer.
grumble Comma expressions are pretty worthless in D grumble

J, 20 bytes
(>:@+:@#.@}.,2^#)@#:

This verb take n and gives us the nth number in the list.  n = 1 produces 1/2, etc...
explanation
(>:@+:@#.@}. , 2 ^ #)@#:
                     @#:  NB. The arg as list of binary digits, feed that to...
             ,            NB. the concatenation of... (first doing the left side)
         @}.              NB. remove the highest order bit and...
      @#.                 NB. convert back to decimal and...
   @+:                    NB. double it and...
 >:                       NB. add one (now we have the numerator)
               2 ^        NB. (now doing the right side) 2 raised to the...
                   #      NB. number of binary digits (the denominator)

Try it online!