Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Finding missing numbers in a list

by ambrus (Abbot)
on Sep 03, 2004 at 15:51 UTC ( [id://388321]=note: print w/replies, xml ) Need Help??


in reply to Finding missing numbers in a list

You can do it with the .. operator:

@a = (41888, 41889, 41890, 41892, 41895); @m = map $a[$_-1]+1..$a[$_]-1, 1..@a-1; print join(" ", @m), $/;

Replies are listed 'Best First'.
Re^2: Finding missing numbers in a list
by Aristotle (Chancellor) on Sep 03, 2004 at 16:01 UTC

    It isn't the easiest to understand, but that's very nice outside the box thinking!

    Update: minor niggles: use $#a since that's what you mean — and please, please, use better variable names.

    my @list = ( 41888, 41889, 41890, 41892, 41895 ); my @missing = map { ( $list[ $_ - 1 ] + 1 ) .. ( $list[ $_ ] - 1 ) } 1 + .. $#list;

    Makeshifts last the longest.

        I'm not convinced that @list is much of an improvement over @a as a name for an array :-)

        Thats a terrible unconviction :P

        @list is much times better than @array ... @a for short...

        because the question talks about a list of numbers, the @list ... and the @ tells us its array

        @numbers

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2024-04-25 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found