You are not logged in.
i'm stuck....brain is in mush state
i'm starting to brute force it, and i thought maybe some of you guys might have an elegant solution.
given a list of numbers; 1,2,3,4,5,6,7,8,9
this will return a single array of [1,2,3,4,5,6,7,8,9]
given this list; 1,2,5,6,7
will return [1,2],[5,6,7]
likewise, this list; 1,2,4,6,8,9
should return [1,2],[4],[6],[8,9]
get the pattern? basically group sequential numbers together. i just started and the only way i can think of doing it is very ugly involving lots of forward and backward comparisons with a lot of collections to keep track of stuff
Offline
Will they always be sorted ascending like your examples?
Offline
yes. i figured it out.
here's the basic pseudo code:
List[List[int]] sections = new;
List[int] current = new;
foreach (number in list) {
current.Add(number)
if not adjacent(number, next number) {
sections.Add(current)
current = new
}
}
current.Add(list number in list)
sections.Add(current)
Offline