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

Re: Golf: overtone calculator

by jynx (Priest)
on Sep 01, 2002 at 19:15 UTC ( #194469=note: print w/replies, xml ) Need Help??

in reply to Golf: overtone calculator

just quickly,

Here's a slightly shorter version that still compiles under strict and warnings. i only have tested it under the single test case above, if it fails others please provide them and i'll try to correct it. Anyway, this weighs in at 66 characters:

sub Harmonics ($$) { #23456789_123456789_123456789_123456789_123456789_123456789_123456789_ for$a(1..pop){$_{sprintf'%.3f',$_[0]*$a/$_}++for 1..$a}sort keys%_ }

Replies are listed 'Best First'.
Re: Re: Golf: overtone calculator
by Django (Pilgrim) on Sep 01, 2002 at 23:18 UTC

    Impressing inner loop, but your sort will fail with $_[1] > 10, because it sorts lexically.

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

      Does this fix the problem? (at 72 chars):
      sub Harmonics ($$) { #23456789_123456789_123456789_123456789_123456789_123456789_123456789_ +12 for$a(1..pop){$_{sprintf'%.3f',$_[0]*$a/$_}++for 1..$a}sort{$a-$b}keys +%_ }
        I'm outta votes right now, but kudos for the $a-$b bit. D'oh..

        Makeshifts last the longest.

        Does this fix the problem?

        Yepp, not only working, but kicking out my sort too!

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194469]
[hippo]: See also Getting Started with Perl for some gentle introductory tutorials.
[thao4]: I don't see where I can post my question. I am french so not good in English
[erix]: go to the bottom of this page: Seekers of Perl Wisdom

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-02-21 09:57 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (276 votes). Check out past polls.