I have a set of numbers List<int>
(for example) : 1, 3, 4, 5, 7, 12, 13, 14, 15, 20, 22, 24, 28, 29, 30
I want to have them grouped as sequential like :
Sequence1 = from 1 amount 1 (1)
Sequence2 = from 3 amount 3 (3, 4, 5)
Sequence3 = from 7 amount 1 (7)
Sequence4 = from 12 amount 4 (12, 13, 14, 15)
Sequence5 = from 20 amount 1 (20)
Sequence6 = from 22 amount 1 (22)
Sequence7 = from 24 amount 1 (24)
Sequence8 = from 28 amount 3 (28, 29, 30)
I know how to do it with a for and checking for each number. Is there an more elegant way or an algorithm, or some sql/lambda command that would help me ?