Given an unordered list of musical pitches, write the shortest program/function (scored in bytes) to sort the list from lowest pitch to highest.
Pitches will be given in scientific pitch notation, consisting of a tone name followed by an octave number. Here, the tone name will be a single letter A–G, possibly followed by a single
b character (representing sharp and flat, respectively). The octave number will be a single digit 0–9.
From lowest to highest, the order of pitches in this notation may be represented as follows:
<--- lower pitch higher pitch ---> _______________________________________________________________ Cb0 C0 C#0 Db0 D0 D#0 Eb0 E0 E#0 Fb0 F0 F#0 Gb0 G0 G#0 Ab0 A0 A#0 Bb0 B0 B#0 Cb1 C1 C#1 Db1 D1 D#1 etc.
In this representation, pitch rises from left to right, so vertically aligned notes (enharmonic pairs) have the same pitch. Each row contains three notes in the order flat, natural, sharp (e.g. Cb0, C0, C#0) and the order of rows within an octave is C, D, E, F, G, A, B. Notice that by a quirk of the notation, the indentation pattern differs for the C and F rows.
Your code may sort enharmonic pitches in any order. For example, given
[D#0, Eb0, D#0] as input, any of
[D#0, D#0, Eb0],
[D#0, Eb0, D#0], and
[Eb0, D#0, D#0] is a valid output.
[A2, B2, C2, D2, E2, F2, G2, A3] -> [C2, D2, E2, F2, G2, A2, B2, A3] [E5, D#5, E5, D#5, E5, B4, D5, C5, A4] -> [A4, B4, C5, D5, D#5, D#5, E5, E5, E5] [E#6, Fb6, B#6, Cb7, C7] -> [Fb6, E#6, Cb7, B#6, C7] or [Fb6, E#6, Cb7, C7, B#6]