Skip to main content
3 of 5
deleted 6 characters in body
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

Jelly,  31  30 bytes

FµḢ“¤ı¶“Œ’ḥ;ṪV×12Ʋ;⁾a#i’Ɗ€Sµ$Þ

A monadic Link that accepts a list of lists of characters and yields a sorted version.

Try it online!

How?

FµḢ“¤ı¶“Œ’ḥ;ṪV×12Ʋ;⁾a#i’Ɗ€Sµ$Þ - Link: notes
                            $Þ - sort by: last two links as a monad:
 µ                             -   monadic chain:
F                              -     flatten (this is to get a copy so we don't
                                              alter what we are sorting in place)
                           µ   -   monadic chain:
  Ḣ                            -     head of note (removes it too)
          ḥ                    -     hash with salt & domain:
   “¤ı¶“Œ’                     -       base 250 numbers = [256628,20]
                                         X = CDEFGAB -> 4,6,8,9,11,13,15
                 Ʋ             -     last four links as a monad:
            Ṫ                  -       tail of note (removes it too)
             V                 -       evaluate as Jelly code -> integer
               12              -       twelve
              ×                -       multiply
                                         Y = 12 × octave
           ;                   -     concatenate -> [X,Y]
                        Ɗ€     -     for each (ie. v in [], ['#'], or ['b']):
                      i        -       first index (or 0) of v in:
                   ⁾a#         -         ['a', '#']
                       ’       -       decrement
                                         O = accidental offsets [], [1], or [-1]
                  ;            -     concatenate -> [X,Y,O]
                          S    -     sum -> X+Y+O = note number
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282