Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Finding missing elements in a sequence (code)

by CubicSpline (Friar)
on Nov 06, 2001 at 21:07 UTC ( [id://123621]=note: print w/replies, xml ) Need Help??


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

The problem is with your argument to the find_holes sub. You're returning an array reference, so why not accept an array reference? Try this:

sub find_holes { my $ref = shift; @list = @$ref; @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; }

This worked as far as I could tell. Hope it helps.

~CS

Update: The others are quite right... this does work they way you had it before. *sigh*

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-20 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found