10
Starting at 1-TET, give equal temperaments that have better and better approximation of the perfect fifth(just ratio 3/2). (OEIS sequence A060528)
The formal description of the sequence, copied from the OEIS:
A list of equal temperaments (equal divisions of the octave) whose nearest scale steps are closer and closer approximations to the ratios of two tones of musical harmony: the perfect 4th, 4/3 and its complement the perfect 5th, 3/2.
Note that by symmetry, the perfect fourth doesn't matter.
Let's say we know that 3 is in the sequence. The frequencies in 3-TET are:
2^0, 2^⅓, 2^⅔
Where 2^⅔
is the closest logarithmic approximation of 3/2
.
Is 4 in the sequence? The frequencies in 4-TET are:
2^0, 2^¼, 2^½, 2^¾
Where 2^½
is the closest approximation of 3/2
. This is not better than 2^⅔
, so 4 is not in the sequence.
By similar method, we confirm that 5 is in the sequence, and so on.
When given an integer n
as input, the output must be the first N numbers of the sequence in order. For example, when n = 7
, the output should be:
1 2 3 5 7 12 29
Sequence description by xnor
The irrational constant \$ \log_2(3) \approx 1.5849625007211563\dots\$ can be approximated by a sequence of rational fractions
$$ \frac{2}{1}, \frac{3}{2}, \frac{5}{3}, \frac{8}{5}, \frac{11}{7}, \frac{19}{12}, \frac{46}{29}, \dots$$
A fraction is included in the sequence if it's the new closest one by absolute distance \$ \left| \frac{p}{q} - \log_2(3)\ \right|\$, that is, closer than any other fraction with a smaller or equal denominator.
Your goal is to output the first \$n\$ denominators in order. These are sequence A060528 (table). The numerators (not required) are given by A254351 (table)
Rules:
- Do not import the sequence A060528 directly.
The format doesn't matter as long as the numbers are distinguishable. In the example above, the output can also be:
[1,2,3,5,7,12,29]
As this is a code-golf, the shortest code in bytes wins.
5Hi and welcome to Code Golf SE! We require that all challenges be self-contained, so a description here of the sequence would be a great help. – AdmBorkBork – 2019-09-24T21:54:39.210
5I'm confused by the description from OEIS. It mentions perfect 4th as well (ratio 4/3), but the challenge is about perfect 5ths (ratio 3/2). I think it also needs explanation that the sequence values are the denominators of the rational approximations. – xnor – 2019-09-24T21:58:47.673
I improved the question. Now vote for reopen, please? – Dannyu NDos – 2019-09-24T22:37:59.853
5I like the challenge, but I find the stuff added to the description still confusing, not knowing much about music. For instance, I don't know what 1-TET or 4-TET are, and nothing seems to show up on Google. I'll try writing an explanation of how I'd describe this sequence. – xnor – 2019-09-24T23:06:31.543
@xnor For example, 12-TET means 12-tone equal temperament. – Dannyu NDos – 2019-09-24T23:16:37.007
1As a small technical point, I'd suggest setting some upper bound on what input n can be given. Due to float precision issues, coded solutions might eventually become inaccurate for large n, making it hard to judge which answers are valid. I think something like n=40, the max of the OEIS table, would be reasonable. – xnor – 2019-09-25T00:02:31.507
3@DannyuNDos Ah yes, the 12-tone equal temperament. That's my favourite instrument – Jo King – 2019-09-25T01:53:50.240
Temparement is a way to define the notes that an instrument can produce; it's not an instrument – Luis Mendo – 2019-09-25T09:43:43.710
2@DannyuNDos Thanks. So the comparison is between 1/2 and log2(1.5), not between 2^(1/2) and 1.5. That should be made clearer in the text – Luis Mendo – 2019-09-25T09:48:13.633