Output numbers, more or less

><>, 40 38 bytes


Try it online!

An appropriate language. For reference ><> itself yields 2,1,2,1.

How it Works:

1v   Initialise the stack as 1 and enter loop
 \i:0(?^  If we're out of input, go to the first line
        3%\ Otherwise mod the input by 3, yielding 0 for < and 2 for >
        -1/Subtract 1 to get -1 and 1 respectively
    -{:}   Copy the previous number and subtract the above from it

 /?:    If the number is not 0, repeat the loop

?\        \+$  Otherwise:
                Increment each number until we reach the original 0
{/        /1:   And enter the first loop again

      ~<    When we're out of input, pop the extra -1 from EOF
   rnr      Output the first number
1v!         Push a 1 
        oa  Print a newline and repeat, popping the extra 1 each time

Haskell, 119 bytes

n%(c:b)|c==b!!0=(n+1)%b|a:s<-2%b,e:z<-r$n%[c]=r z++last(max:[min|c>'<'])a e:s

Try it online!


The idea here is that we have runs of either >s or <s, which each map to ascending and descending ranges. So we use group to split the string into groups of consecutive characters. Our job is to then stitch these together in the proper fashion.

When we have <> we want to stitch the two lists together taking the larger end value for example


is split

<<<<<<  >>

mapped to ranges

[1,2,3,4,5,6,7] [3,2,1]

Then when we stitch we drop 3 because it is smaller (3 isn't larger than 7).


When we have >< we do the opposite, we drop the larger value.

The actual code attains this by making an operator %. The definition of % is quite complex, but basically it reads from left to right keeping track of how many consecutive characters are the same. It does this in the left had value of the operator. When we reach a place where the characters change we perform the stitching as I described.

Python 3, 93 bytes

for r in input().split('<'):p=len(r);print(max(k,p)+1,*range(p,0,-1),end=' ');k=1+(p<1)*k

Try it online!


# offset, will be explained later
k = 0 
for run in input().split('<'):
    # p = length of sequence of '>'s, which will produce p+1 decreasing integers
    p = len(run)
    # will print:
    # p+1 p p-1 ... 1    or    k+1 p p-1 ... 1
    print(max(k, p) + 1, *range(p, 0, -1), end=' ')
    # offset of the next sequence: (i.e. -1 + the minimal value of the first integer)
    k = 1 + (k if p > 0 else 0)