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.
x: basic frequency (Hz) (number > 0) n: maximum harmonic factor (integer > 0)
( x <= y ) &&( y <= n * x )
=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?"
In reply to Golf: overtone calculator by Django
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |