Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Finding missing elements in a sequence (code)

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


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

Hmm, what are you expecting and how are you calling your function?

It seems to "work" for me.

#!/usr/local/bin/perl -w use strict; 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; } my @foo = qw(1 2 5 6 9); my $vac = find_holes(\@foo); print "@$vac\n"; __END__ $ ./holes.pl 3 4 7 8

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-16 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found