Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Finding missing numbers in a list

by TrekNoid (Pilgrim)
on Sep 03, 2004 at 16:16 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://388328]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-19 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found