User JWinslow23 brought this up in chat yesterday: What's the fastest way to determine whether a list of six or so musical notes represented by numbers from 0 to 12 is "musical"; that is, all the notes fall within the same major scale?
I couldn't wait for him to start a topic, so I'm posting my code here. With the list in L1:
Code:
Where each "badmask" is a 12 element list of the notes *not* in a certain major scale. For example, badmask1 would be:
Code:
I have a feeling there's a faster solution. Ideas:
Instead of masking with lists, use prime factors and remainder(. That is, use the first 12 primes; the masks would be the primes multiplied together that correspond to the notes in a certain musical scale. min(remainder({goodMasks},notes)) would give a 1 if for each mask, there is a prime in "notes" that isn't in that mask.
I don't know which is faster; testing must be done.
I couldn't wait for him to start a topic, so I'm posting my code here. With the list in L1:
Code:
1-min(L1)+L1->L1
0 and binompdf(12,0->L2
For(X,1,dim(L1
1->L2(L1(X
End
not(max(L2 and {badmask1}) and max(L2 and {badmask2}) and ... and max(L2 and {badmask8})
Where each "badmask" is a 12 element list of the notes *not* in a certain major scale. For example, badmask1 would be:
Code:
{0,1,0,1,0,0,1,0,1,0,1,0}
I have a feeling there's a faster solution. Ideas:
Instead of masking with lists, use prime factors and remainder(. That is, use the first 12 primes; the masks would be the primes multiplied together that correspond to the notes in a certain musical scale. min(remainder({goodMasks},notes)) would give a 1 if for each mask, there is a prime in "notes" that isn't in that mask.
I don't know which is faster; testing must be done.