**From New Scientist #2341, 4th May 2002** [link]

The relative frequencies of the notes of the diatonic music scale are:

C = 24, D = 27, E = 30, F = 32, G = 36, A = 40, B = 45, C’ = 48.

I recently built a series of oscillators so that I could hear how it sounded, but something went wrong with the wiring, so that I ended with an eight-note keyboard where only two were in the correct places.

However, when I played each key in order from the left, I noticed that the only intervals between adjacent notes were fourths (frequency ratio 4/3 or 3/4), fifths (3/2 or 2/3), or sixths (5/3 or 3/5).

Further, the interval (frequency ratio) between the two notes I did get right was one of these.

(a) If I played the left-hand key, what note letter did it sound?

(b) Could the notes have been arranged according to the same rules and have none in the right place?

(c) Could the notes have been arranged according to the same rules and have had more than two in the right place?

[enigma1185]

### Like this:

Like Loading...

This Python program runs in 56ms.

Solution:(a) The left-hand key sounds note A; (b) Yes; (c) No.For (a) the keys are (40, 30, 45, 27, 36, 24, 32, 48) with 36 and 48 in the correct positions.

The ratios between adjacent notes are (4/3, 2/3, 5/3, 3/4, 3/2, 3/4, 2/3).

For (b) there are several possible arrangements (given below, along with the ratios):

(30, 45, 27, 36, 48, 32, 24, 40), (2/3, 5/3, 3/4, 3/4, 3/2, 4/3, 3/5)

(32, 48, 36, 27, 45, 30, 40, 24), (2/3, 4/3, 4/3, 3/5, 3/2, 3/4, 5/3)

(45, 30, 40, 24, 32, 48, 36, 27), (3/2, 3/4, 5/3, 3/4, 2/3, 4/3, 4/3)

(48, 32, 24, 36, 27, 45, 30, 40), (3/2, 4/3, 2/3, 4/3, 3/5, 3/2, 3/4)

(48, 32, 24, 40, 30, 45, 27, 36), (3/2, 4/3, 3/5, 4/3, 2/3, 5/3, 3/4)

For (c), there are no arrangements with more than two notes in the correct position (all layouts have 0, 1 or 2 notes in the correct position). Which means we don’t have to consider how to extend the condition stated as “the interval (frequency ratio) between the two notes I did get right was one of these” to more than two notes in the correct position.

This is a little slow, but as short as I could make it easily.

#artcode #programmingasanartform #codeart

The computer gives a result for (A) of 40, (B) a resounding yes and (C) a resounding NO! It only takes a few seconds to run, which is much faster than I could do it in my head! I tried to take some of your advice from the last question on board, I hope that’s evident in the efficiency of my code! Thanks again!

@liam: I don’t know if you want any hints, but if you are happy to use routines from Python’s standard library you could save yourself some typing replacing lines 2-18 with a single statement:

See the Python documentation on the

itertoolspackage for more details. It’s got quite a few useful routines for solvingEnigmatype problems (permutations(),combinations(),product()andcount()are the most useful).I tried a permutation solution and initially got four solutions. Some further manual analysis, listed in the comments in the code below gave the same note sequence as Jim and the same answers for parts (a), (b) and (c), which are initially commented out in the code below: