Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Golf code in perl

by tt08 (Initiate)
on Mar 11, 2017 at 10:07 UTC ( [id://1184257]=note: print w/replies, xml ) Need Help??


in reply to Re: Golf code in perl
in thread Golf code in perl

Yes i have posted the question first on stackoverflow and they suggested me perlmonks would help you.Can you please help me?

Replies are listed 'Best First'.
Re^3: Golf code in perl (updated)
by haukex (Archbishop) on Mar 11, 2017 at 10:52 UTC
    Yes i have posted the question first on stackoverflow and they suggested me perlmonks would help you.

    Could you provide a link? At the link I posted above there is no such reference to PerlMonks.

    Can you please help me?

    Well, first of all, it seems the code you posted doesn't work, as opposed to what was posted on StackExchange, so I'll look at the latter.

    $ cat input.txt 5 5 6 11 16 7 12 $ perl -e '@j=split$",<>;print$% map$%+=2*$q[$_%@j[1]]++,split$",<>' i +nput.txt $ perl -e '@j=split$",<>;map$r+=2*$a[$_%@j[1]]++,split$",<>;print$r' i +nput.txt 8

    I take it you're not allowed any switches like e.g. -F? Anyway, here's one idea:

    $ perl -e '<>=~/\d+$/;map$r+=2*$a[$_%$&]++,split$",<>;print$r' input.t +xt 8

    Update: That's 50 chars... what do I win? ;-) Update 2: tybalt89 shows how it's done, very nice :-)

      http://stackoverflow.com/questions/42733000/code-golf-in-perl? This is the link where the question was posted and – simbabque told me perl monks would be better .You can check his comment.And we are not allowed switches like -F. Your one idea helped me.Thanks,mate.Could you further reduce it ?Can we replace split$",<> with something?You are a true helper bro.#respect from my side.
      Thanks a ton @tybalt89

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-24 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found