Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Better way of writing "find the missing number" -- oneliner

by Discipulus (Canon)
on Apr 04, 2017 at 07:29 UTC ( [id://1186955]=note: print w/replies, xml ) Need Help??


in reply to Re: Better way of writing "find the missing number(s)"
in thread Better way of writing "find the missing number(s)"

ah! given the above task the oneliner is much simpler!

perl -E "@ar=(1..3,5,6,7);$h{$_}++for$ar[0]..$ar[-1];delete$h{$_}for@a +r;print keys %h" 4

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: Better way of writing "find the missing number(s)" -- oneliner
by tybalt89 (Monsignor) on Apr 04, 2017 at 07:50 UTC

    Slices, slices...

    perl -E '\@h{1..(@a=(1..3,5,6,7))+1};delete@h{@a};say%h'
Re^3: Better way of writing "find the missing number" -- oneliner
by salva (Canon) on Apr 04, 2017 at 07:50 UTC
    hey, let's play golf!
    perl -e'$_>++$i&&die"$i\n"for 1..3,5,6,7'
Re^3: Better way of writing "find the missing number" -- oneliner
by tybalt89 (Monsignor) on Apr 04, 2017 at 08:44 UTC

    Or an array version.

    perl -E '@b=0..(@a=(1..3,5,6,7))+1;@b[0,@a]="";say@b'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-23 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found