Musical Notes and Intervals

Problem #62

Tags: music instructional

Who solved this?

Previous:Pixel Circles Next:Scales and the Circle of Fifths


Two Octaves of a Piano

A section of a piano keyboard. Most full pianos have 88 keys.

Nearly modern music is made up of notes - tones with defined pitch. For now we won't worry about the pitches, and focus instead on the names of the notes themselves.

If we look at the piano keyboard above, we can see that the notes exists in repeating sections called "Octaves". Each Octave contains 12 notes total - 7 "natural" notes on white keys, and 5 "sharp" notes on the black keys. So in order, the notes are C, C#, D, D#, E, F, F#, G, G#, A, A#, B, which would then continue at the next octave again starting at C.

The space between two consecutive notes is called a "half step", and the total space between two notes is called the Interval. The following chart details the interval names.

Also understand that while adding a "sharp" # to any note raises it by a half step, likewise adding a "flat" b to any note lowers it by a half step. In this way notes like C# and Db are actually the same note. The same also goes for E and Fb.

# of Half Steps Interval Name Interval Abbreviation Example
0 Perfect Unison P1 C → C
1 Minor 2nd m2 C → C#
2 Major 2nd M2 C → D
3 Minor 3rd m3 C → D#
4 Major 3rd m2 C → E
5 Perfect 4th P4 C → F
6 Tritone TT C → F#
7 Perfect 5th P5 C → G
8 Minor 6th m6 C → G#
9 Major 6th M6 C → A
10 Minor 7th m7 C → A#
11 Major 7th M7 C → B
12 Perfect Octave P8 C → C

Problem Statement

Input Data
First line will be Q, the quantity of testcases.
Q lines will follow, each containing two note names N1 N2. Assume that N2 is the next-highest note above N1 bearing that name.

Answer
Should be Q space-separated Interval abbreviations, corresponding to the intervals between each given N1 N2 pair.

Example

input data:
4
C G
G# B
B# Cb
A# Bb

answer:
P5 m3 m7 P8
You need to login to get test data and submit solution.