Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Is it so different from yours?

Nested map's -v- nested for's

Instead of using sprintf, I multiply the result by 1e3 int it and divide by 1e3 again.

Which bit gave you problem's?

BTW. I noted your comment re: jynx's and lexical sorting when n>10, and realise that mine suffers the same flaw. So, numerisising(is that a word?) the sort, I got

#! perl -w sub H($$){ #________1_________2_________3_________4_________5_________6_________7 +_________8____ #234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234 map{int(1e3*$_*$_[0])/1e3}grep!$_{$_}++,sort{$a<=>$b}map{$.=$_;map$./$ +_,1..$_}1..pop }

The extra 9 chars* cost me dear, and you were winning by 3, but I couldn't have that so...for a round of 76:

sub H($$){ #________1_________2_________3_________4_________5_________6_________7 +______ #234567890123456789012345678901234567890123456789012345678901234567890 +123456 map{$.=$_,map$_{int($_[0]*1e3*$./$_)/1e3}++,1..$_}1..pop;sort{$a<=>$b} +keys%_ }

but that meant using a map in a void context so for the same 76, but avoiding that pesky map

sub H($$){ #________1_________2_________3_________4_________5_________6_________7 +______ #234567890123456789012345678901234567890123456789012345678901234567890 +123456 $.=$_,map$_{int($_[0]*1e3*$./$_)/1e3}++,1..$_ for 1..pop;sort{$a<=>$b} +keys%_ }

By now the light was fading and it was hard to keep my eye on the ball, so bad light stopped play and the tournement can resume tomorrow with jynx first to step up to the tee:)

Update However, during floodlite play, (and stealing jynx's best bits), and retaining the more aesethically pleasing trailing zero suppression:), I give you this for 71

sub H($$){ #________1_________2_________3_________4_________5_________6_________7 +_ #234567890123456789012345678901234567890123456789012345678901234567890 +1 for$.(1..pop){$_{int($_[0]*1e3*$./$_)/1e3}++for 1..$.}sort{$a-$b}keys% +_ }

* I officially motion, on behalf of golfer's everywhere, that Perl6 have a sortn built-in that assumes the $a<=>$b. (Along with rev as an alias for reverse 8^).


Well It's better than the Abottoire, but Yorkshire!

In reply to Re: Re: Re: Golf: overtone calculator by BrowserUk
in thread Golf: overtone calculator by Django

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found