Just another simple math challenge:
Write a subroutine that returns a list of all even harmonics (overtones) of a given frequency and their indirect harmonics up to a given factor.
arguments:
the returning list must be sorted (min .. max value) and each value (y) must be within the following range:
The values must be unique and rounded to 3 digits after decimal point.
x: basic frequency (Hz) (number > 0) n: maximum harmonic factor (integer > 0)
the returning list must be sorted (min .. max value) and each value (y) must be within the following range:
( x <= y ) &&( y <= n * x )
The values must be unique and rounded to 3 digits after decimal point.
=for Example: sub Harmonics ($$) { ...add your code here... } print join( "\n", Harmonics( 100, 6 ) ); # would print the following (without comments): 100.000 # 100 * 1/1 120.000 # 100 * 6/5 125.000 # 100 * 5/4 133.333 # 100 * 4/3 150.000 # 100 * 3/2 166.667 # 100 * 5/3 200.000 # 100 * 2/1 250.000 # 100 * 5/2 300.000 # 100 * 3/1 400.000 # 100 * 4/1 500.000 # 100 * 5/1 600.000 # 100 * 6/1 =cut
Here's my little program, with a subroutine of 81 chars and warnings enabled:
|
update: no trailing zero supression was intended (fixed the example).
Thanx to BrowserUK for looking closely.
~Django
"Why don't we ever challenge the spherical earth theory?"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Golf: overtone calculator
by BrowserUk (Patriarch) on Sep 01, 2002 at 19:49 UTC | |
by Django (Pilgrim) on Sep 01, 2002 at 23:24 UTC | |
by BrowserUk (Patriarch) on Sep 02, 2002 at 02:01 UTC | |
by Arien (Pilgrim) on Sep 02, 2002 at 05:31 UTC | |
by BrowserUk (Patriarch) on Sep 02, 2002 at 07:35 UTC | |
by Django (Pilgrim) on Sep 02, 2002 at 07:08 UTC | |
Re: Golf: overtone calculator
by jynx (Priest) on Sep 01, 2002 at 19:15 UTC | |
by Django (Pilgrim) on Sep 01, 2002 at 23:18 UTC | |
by jynx (Priest) on Sep 02, 2002 at 01:37 UTC | |
by Aristotle (Chancellor) on Sep 02, 2002 at 02:07 UTC | |
by Django (Pilgrim) on Sep 02, 2002 at 06:43 UTC | |
Re: Golf: overtone calculator
by Aristotle (Chancellor) on Sep 02, 2002 at 02:01 UTC | |
Re: Golf: overtone calculator
by tadman (Prior) on Sep 02, 2002 at 09:04 UTC | |
by mtve (Deacon) on Sep 03, 2002 at 13:15 UTC | |
by Django (Pilgrim) on Sep 02, 2002 at 10:32 UTC | |
by tadman (Prior) on Sep 02, 2002 at 13:26 UTC | |
by theorbtwo (Prior) on Sep 02, 2002 at 23:55 UTC | |
by BrowserUk (Patriarch) on Sep 03, 2002 at 00:17 UTC | |
by tadman (Prior) on Sep 03, 2002 at 05:35 UTC |
Back to
Meditations