Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Golf: overtone calculator

by Django (Pilgrim)
on Sep 01, 2002 at 23:24 UTC ( [id://194486]=note: print w/replies, xml ) Need Help??


in reply to Re: Golf: overtone calculator
in thread Golf: overtone calculator

Trailing zero supression wasn't intended (fixed it).
Would you mind explaining your code? I'm just examining it for the nth time and still can't get no grip on it...

~Django
"Why don't we ever challenge the spherical earth theory?"

Replies are listed 'Best First'.
Re: Re: Re: Golf: overtone calculator
by BrowserUk (Patriarch) on Sep 02, 2002 at 02:01 UTC

    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!

      Shamelessly stealing from jynx and you, I contribute my meager -2 strokes for 69:

      #________1_________2_________3_________4_________5_________6_________ #23456789012345678901234567890123456789012345678901234567890123456789 for$a(1..pop){$_{1e-3*int"@_"*1e3*$a/$_}++for 1..$a}sort{$a-$b}keys%_

      — Arien

        One word ...er... begins with B and engineers use it to describe a particular coarse file! I really thought I'd milked that one. ++Arien.


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

      OK, thanks for the notes - I think I got it now.
      What confused me with your first attempt were quite a few things:
      nested maps, that 1e3 trick, the freakish use of $. and especially that sick thing:
      grep !$^H { $_ }++
      Your current version is much straighter (not saying less tricky), and admittedly trailing zero suppression IS aesthetically more pleasing (shame on me!).

      ~Django
      "Why don't we ever challenge the spherical earth theory?"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-28 21:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found