I have an array of numbers (C#):
int[] seq = new[] { 2, 1, 4, 2, 1, 3,
0, 0, 0, 0, 0,
1, 5, 2, 3, 7,
0, 0, 0,
1, 2, 3,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
For the sequence above I need something like this:
"Group1" - [0, 0, 0, 0, 0]
"Group2" - [0, 0, 0]
"Group3" - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
This looks like you're putting consecutive zeros into groups. I would store your results in a
Dictionary<string, List<int>>
and you'll have to know when you find a zero you create a new group and every consecutive zero will belong to the same group until the sequence is broken. Then a new group is started when the next zero is found, and so on.Something like:
Results: