Morlane has asked for the wisdom of the Perl Monks concerning the following question:
Looking for some perl magic.
Given an arbitrarily long list of numbers that SHOULD be consecutive, is there a simple method of finding any missing numbers?
For instance, given ( 41888, 41889, 41890, 41892, 41895 ), i'd like to determine that 41891, 41893 and 41894 are missing?
I've considered populating an array, indexed by my list, then looking for missing indexes, but I don't care for changing the start index of my arrays, and with the numbers I'm using, I'd have a LOT of empty indexes before I get to my first data.
I've also considered a simple loop that compares x to x+1, and steps x thru the list, but that seems kind of clunky to me.
I'm hoping for some perl elegance.
Morlane
Given an arbitrarily long list of numbers that SHOULD be consecutive, is there a simple method of finding any missing numbers?
For instance, given ( 41888, 41889, 41890, 41892, 41895 ), i'd like to determine that 41891, 41893 and 41894 are missing?
I've considered populating an array, indexed by my list, then looking for missing indexes, but I don't care for changing the start index of my arrays, and with the numbers I'm using, I'd have a LOT of empty indexes before I get to my first data.
I've also considered a simple loop that compares x to x+1, and steps x thru the list, but that seems kind of clunky to me.
I'm hoping for some perl elegance.
Morlane
|
---|
Back to
Seekers of Perl Wisdom