So basically it checks the sequence by iterating through the pre-sorted array until there's a gap in the sequence. Then just checks whether the end value is the same as last value seen in the iteration.use strict; ## I've lazily pre-sorted these ;) my @ars = ( [ qw/ 1 2 3 4 5 / ], [ qw/ 1 2 3 4 6 / ], [ qw/ 2 3 4 6 7 / ], ); for(@ars) { print "broken list: @$_\n" and next if $_->[0] != 1; my($i, $n) = 0; $n = $_->[$i] while $i <= $#{$_} and $_->[$i] + 1 == $_->[++$i]; print "woo: @$_\n" if $n == $_->[-1]; print "doh: sequence broke at index ${\($i - 1)} (@$_[$i - 1,$i])\n" if $n != $_->[-1]; } __output__ woo: 1 2 3 4 5 doh: sequence broke at index 3 (4 6) broken list: 2 3 4 6 7
_________
broquaint
In reply to Re: Validate array of numbers in sequence
by broquaint
in thread Validate array of numbers in sequence
by AcidHawk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |