Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Finding missing elements in a sequence (code)

by clemburg (Curate)
on Nov 06, 2001 at 21:04 UTC ( #123619=note: print w/ replies, xml ) Need Help??


in reply to Finding missing elements in a sequence (code)

Huh? How do you call it? This runs fine on my machine:

sub find_holes { my @list = @{ shift() }; @list = sort { $a <=> $b } @list; my $low = $list[0]; my $high = $list[-1]; my %isthere = map { $_ => 0 } ($low..$high); $isthere{$_} = "yes" for @list; my @vacancies = grep { not $isthere{$_} } sort keys %isthere; return \@vacancies; } print "@{find_holes([qw(0 1 2 3 4 6 8)])}\n";

Prints:

d:\tmp\try>perl try.pl perl try.pl 5 7 d:\tmp\try>

Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com


Comment on Re: Finding missing elements in a sequence (code)
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2015-07-07 02:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls