Given two notes, inputted as strings or lists/arrays, calculate how many semitones apart they are (inclusive of the notes themselves), outputting as a number.
Explanation of a semitone:
A semitone is one step up or down the keyboard. An example is C to C#. As you can see below the note C is on a white note and C# is the black note just one above it. Semitones are the leaps from a black note to the next white note, up or down, except for:
- B to C
- C to B
- E to F
- F to E
'A, C' -> 4
'G, G#' -> 2
'F#, B' -> 6
'Bb, Bb' -> 13
- The largest distance between two notes is 13 semitones.
- The second inputted note will always be above the first inputted note.
- You can take input as either a string, or an array/list. If you take it as a string, the notes will be comma-separated (e.g.
String -> 'A, F',
Array -> ['A', 'F']).
- You can assume that you will always be given two valid notes.
- Sharps will be denoted as
#and flats will be denoted as
- Your code must support enharmonic equivalents (e.g. It must support both F# and Gb)
- Your code does not need to support notes that are named with, but can be named without a sharp or flat (i.e. You do not need to support E#, or Cb). Bonus points if your code does support it though.
- Your code does not need to support double sharps or double flats.
- You can assume that if you get the both the same notes, or same pitch (e.g. 'Gb, Gb' or 'A#, Bb'), the second not will be exactly one octave above the first.
- This is code golf so the answer with the least amount of bytes wins.
G -> G#because they're both included. \$\endgroup\$
E#? What about double sharps/flats? \$\endgroup\$
(X, Y]so C to C# is 1 semitone and C to C is 12 semitones. \$\endgroup\$