Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liammclennan/aa1b3a5e74eb3ff01898 to your computer and use it in GitHub Desktop.
Save liammclennan/aa1b3a5e74eb3ff01898 to your computer and use it in GitHub Desktop.
Pitch frequency code puzzle
Write a function that calculates the number of semitones between two musical notes.
The notes are [A;ASharp;B;C;CSharp;D;DSharp;E;F;FSharp;G;GSharp].
The distance between each is 1 semitone. E.g. ASharp -> E = 6 semitones.
Twist: The notes can be in 3 different octaves. E.g. ASharp (octave 1) -> E (octave 2) = 18 semitones.
Extra credit: If A (octave 1) is 220Hz write a function that calculates the frequency of a note in an octave.
E.g. Frequency(A, 1) == 220, Frequency(A,2) == 440 etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment