Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Finding missing numbers in a list

by TrekNoid (Pilgrim)
on Sep 03, 2004 at 16:16 UTC ( #388328=note: print w/replies, xml ) Need Help??


in reply to Finding missing numbers in a list

Here's my approach... assuming the list is always sorted:

my @list = (41888, 41889, 41890, 41892, 41895); my $lo = $list[0]; my $hi = $list[$#list]; my $idx = 0; for ($cnt=$lo;$cnt<=$hi;$cnt++) { if ($cnt == $list[$idx]) { $idx++; } else { print "Missing: $cnt\n"; } }
Trek

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://388328]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2020-09-29 14:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (146 votes). Check out past polls.

    Notices?