in reply to Validate array of numbers in sequence
An even simpler way to do this would be to add all of the numbers up. This also has the performance benefit of avoiding the sort entirely.
For example:-
my $total = 0; my $expect = 0; for(int i=0;i<@array;i++) { $total += $array[$i]; $expect += $i; Correction: $expect += $i + 1; } return 1 if ($total == $expect);
Aaarrrggghhh - sorry, ignore this post. As has been pointed out, it doesn't work.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Validate array of numbers in sequence
by Roger (Parson) on Sep 08, 2003 at 22:50 UTC |