Ordered sequence of ascending integer combinations Write a program or function to produce the following output in the correct order.

EDIT: The symbols are not mathematical! The numbers just represent unique data and the + and - could be any two arbitrary symbols.

Take an non-negative integer input n. The first line is always -, even for n=0.


If the current line is -, the next line is 1+2+ ... (n-1)+n-


n=4: - => 1+2+3+4-

If the last integer is equal to n, remove all integers from the end that are immediately followed by a -, then change the last + to a -


n=4: 1-2+3-4- => 1-2-
EDIT: When the string is full (all the integers from 1 to n are included), remove all integers from the end that are followed by a -, until you reach an integer followed by a +. Leave that integer but change its following + to a -
Using the same example as immediately above (which does not follow -), remove 4-, remove 3-, change 2+ to 2-. 1- doesn't change since we stop at 2. Result:  1-2-

If the last integer is less than n, append the remaining integers with a + after each one, except the final integer which should have a - appended


n=4: 1+2- => 1+2-3+4-
EDIT: If the current string is not full (does not contain all the integers from 1 to n), add each integer not already included in ascending order up to n-1 with a + after each one, and then append the last integer n followed by a -
If the current line is 1-, append 2+, append 3+ which is n-1 if n=4. Then append 4-. Result: 1-2+3+4-

If the current line contains all the integers and each one is immediately followed by a -, exit the code


n=4: 1-2-3-4- => END



There must be no leading or trailing spaces on any line. There must be a line break between each line. There may or may not be a line break on the last line.

EDIT: You should test your code up to at least n=10 (over 1000 lines of output so I can't include it here). Any number that doesn't cause your code to run out of resources should (eventually!) produce the correct output but you don't have to wait for the universe to end!

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

Input n=0:

-


Input n=1:

-
1-


Input n=2:

-
1+2-
1-
1-2-


Input n=4:

-
1+2+3+4-
1+2+3-
1+2+3-4-
1+2-
1+2-3+4-
1+2-3-
1+2-3-4-
1-
1-2+3+4-
1-2+3-
1-2+3-4-
1-2-
1-2-3+4-
1-2-3-
1-2-3-4-
Haskell, 89 bytes

g takes an integer and returns a string.



g n=unlines$max"-".foldr(\(s,i)r-&gt;id=&lt;&lt;[show i++s:r|s:r&gt;"+"])""&lt;$&gt;mapM(mapM(,)"+-")[1..n]


Try it online!

How it works


Loosely speaking, the algorithm constructs a list of all 2^n combinations 1+2+...n+, 1+2+...n- up to 1-2-...n-, strips away the final +-terminated numbers, and if the result is empty, replaces it with -.
mapM(,)"+-" is a shorter way (using the function monad) to write \i-&gt;[('+',i),('-',i)].
mapM(mapM(,)"+-")[1..n] generates (using the list monad for the outer mapM) a list with all combinations as lists of tuples e.g. [(1,'+'),(2,'-'),...,(n,'+')].
foldr ... &lt;$&gt; ... combines each of these lists of tuples into a string, using the lambda expression to build it from the right.


(s,i) is a tuple of a sign and a number, and r is the string constructed from the tuples to its right.
id=&lt;&lt;[show i++s:r|s:r&gt;"+"] prepends i and s to the string r constructed so far, but not if the sign s is positive and r is empty.


This is tested by comparing s:r to "+". By luck this is the lexicographically smallest string that can result from concatenating them, so the comparison can use &gt; rather than /=.


Also by luck, "-" is smaller than any nonempty string that can be constructed by the fold, so the empty string can be replaced with it by using max.
Finally unlines turns the strings into a single string of lines.