Is it so different from yours?
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^).
In reply to Re: Re: Re: Golf: overtone calculator
by BrowserUk
in thread Golf: overtone calculator
by Django
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |