The year is 930, and the Gregorian Church is having a problem. They have thousands of pages of chant music, but the problem is that all the sheet music was simply thrown onto a pile instead of having any real organisation system:
Image by user gamerprinter at Cartographers' Guild.
The Church needs to organise all the sheet music, so they have hired a medieval software engineer to write a program to organise it for them. You are the software engineer that has been hired. However, the compilation process in medieval times involves the program being written onto paper by a team of slow biblical scribes. To decrease the time it takes for the team of scribes to compile your code, you must make the program as small as possible.
The Church wants the chant music to be organised based off the musical scale they are written in. All of the Church's chant music is written in Dorian scales. Given the notes of a certain piece of music, your program will output the Dorian scale that it is in. Here, I will explain exactly what a Dorian scale is. If you already know, you may skip this section.
There are 12 possible notes in any melody. Here they are in order:
C C# D D# E F F# G G# A A# B
A semitone (represented using a S
) is incrementing one step to the right, wrapping around (so a semitone up from B would be back to C). A tone (represented using a T
) is two semitones. For instance, a semitone up from F# would be G. A tone up from F# would be G#.
To create a Dorian scale, we start from any note in the list, and then move up in the following pattern, listing the notes that we encounter:
T, S, T, T, T, S
An example. I start from A. The notes of my Dorian scale becomes:
A
B (up a tone)
C (up a semitone)
D (up a tone)
E (up a tone)
F# (up a tone)
G (up a semitone)
The scale has the notes A, B, C, D, E, F#, and G. Because I started from A, we will call this the Dorian scale in A. There are therefore 12 different Dorian scales, each of which are named after the note that they started from. Each of them use the same pattern of tones and semitones, just starting from a different position. If my explanation is not coherent you may also consult Wikipedia.
The input of the program can be given from whatever is appropriate for your program (e.g. STDIN, command line argument, raw_input()
). It may be not pre-initialised in a variable. The input will be a list of comma seperated notes, representing the melody of the piece. There may be repeated notes. There will always be enough different notes in the input to be able to decisively deduce the scale of the piece. An example input:
B,B,D,E,D,B,A,G#,A,G#,E,D,F#,E,F#,E,F#,G#,A
The output of the program should be the string Dorian scale in X
, where X is the starting note of the scale. The output of the example input:
Dorian scale in B
Comparing this with the Dorian scale in B (B C# D E F# G# A
) we see that all the notes of the melody are within this scale. The note C# is unused in this case. However there are sufficient notes to unambiguously identify B Dorian as the correct key. No other Dorian scale fits, because whatever other scale we try, there is always at least one note of the melody that does not belong to the scale.
This is code golf, so the entry with the shortest number of characters wins. Ask in the comments if you have questions.