If I understand correctly, you want to insert “delimiters” in the list in order to split it. Taking your example and using the symbol |
to indicate the delimiter
1 2 3 1 2|3 1|2 3 1|2|3
- the decisions you need.
In a list (I call it a list, not a collection, because you need order) of n
elements, there are potential n-1
positions for the separator. There are two positions in the above example. At each position, a separator may or may not be present.
You can use the binary representation of numbers from 0
to 2^(n-1) - 1
to list all possible separator locations. In your example, it will be a number from 0..3.
0: 00 1: 01 2: 10 3: 11
Szabolcs
source share