Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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