48
3
Given a length N string of less-than and greater-than signs (<
, >
), insert the integers 0 through N at the start and end and in between each pair of signs such that all the inequalities are satisfied. Output the resulting string. If there are multiple valid outputs, output any one (and just one) of them.
For example
<<><><<
has 7 characters so all the numbers from 0 to 7 inclusive must be inserted. A valid output is
2<3<4>1<5>0<6<7
because all the inequalities taken one at a time
2<3
3<4
4>1
1<5
5>0
0<6
6<7
are true.
If desired, the output may have spaces surrounding the signs, e.g. 2 < 3 < 4 > 1 < 5 > 0 < 6 < 7
.
The shortest code in bytes wins.
Test Cases
The first line after an empty line is the input and the next line(s) are each valid output examples.
[empty string]
0
<
0<1
>
1>0
<<
0<1<2
<>
1<2>0
><
1>0<2
2>0<1
>>
2>1>0
<<<
0<1<2<3
><>
1>0<3>2
>><
3>2>0<1
3>1>0<2
2>1>0<3
>>>
3>2>1>0
>>><<<
3>2>1>0<4<5<6
6>3>1>0<2<4<5
4>2>1>0<3<5<6
4>3>1>0<2<5<6
<<><><<
2<3<4>1<5>0<6<7
>><><>>
7>6>0<5>1<4>3>2
<<<<<<<<<<<<<<
0<1<2<3<4<5<6<7<8<9<10<11<12<13<14
>><<<<><>><><<
6>5>4<7<8<9<10>3<11>2>1<12>0<13<14
14>5>4<7<8<9<10>3<11>2>1<12>0<13<6
4Will there always be a valid output? – mbomb007 – 2016-09-06T21:51:09.363
3@mbomb007 Yes. There always is at least one. – Calvin's Hobbies – 2016-09-06T21:52:25.813
23I want to see someone program this in ><>! That would be awesome (and ironic I guess?) – Soren – 2016-09-06T23:25:07.370
This was a really fun but simply challenge, thanks op – Shaun Wild – 2016-09-07T15:00:14.553
Not sure if you're listing all valid outputs or just some example possible outputs, but if the first, test case
<>
can also be0<2>1
as possible valid output. – Kevin Cruijssen – 2020-01-16T11:23:31.160