in reply to Consecutive number checking
Assuming the list of number is sorted, and contains no duplicates, you can tell if a "streak" occurs just by peeking ahead.
for (my $i = 0; $i < @array - $streak_len; $i++) { print "$array[$i] .. " . $array[$i] + $streak_len . "\n" if $array[$i+$streak_len] == $array[$i] + $streak_len; }
The disadvantage with this method is that it (a) reports overlapping streaks and (b) doesn't maximize streaks. (A) is easy to fix; when you find a streak, increment the index immediately by $streak_len.
|
|---|