The task is to group adjacent values from collection and output it as a new aggregated collection.
Consider we have following input:
Sequence Number Value ======== ===== 1 9 2 9 3 15 4 15 5 15 6 30 7 9
The aim is to enumerate over Sequence Numbers and check if the next element has the same value. If yes, values are aggregated and so, desired output is as following:
Sequence Sequence Number Number From To Value ======== ======== ===== 1 2 9 3 5 15 6 6 30 7 7 9
Build a code with following assumptions:
- Sequence Numbers are already ordered in input table.
- There can be gaps in Sequence Numbers. If input contains gaps, output should contain gaps too. For example input
1 99\n2 99\n4 99\n6 99
, output will be1 2 99\n4 4 99\n6 6 99
. - Assume Value is type of integer.
- It can be a full program or just a function.
- This cruft
(Sequence Sequence\n
...======== ======== =====\n)
is not a part of output. Output format is not defined; there should be a delimeter between values and between rows, so anyone can distinguish values and rows.
It's an extend of my StackOverflow question: https://stackoverflow.com/questions/14879197/linq-query-data-aggregation.
Sequence Sequence\n
...======== ======== =====\n
) part of the expected input and output? If not, can you please specify the expected formats? \$\endgroup\$