Please in order to save solutions and appear on the leaderboards.

Musical Chords

by GolfingSuccess , Irratix , MeWhenI , NewDefectus

Details

For each set of three musical notes forming a triad, print the name of the chord they form, consisting of the root note and the type of triad.

Each note is represented as an uppercase letter, optionally followed by a single accidental, either sharp ( U+266F) or flat ( U+266D).

Background:

There are twelve pitch classes in twelve-tone equal temperament, some of which have multiple names due to and raising and lowering the pitch, respectively. They are, in ascending order:

#Name 1Name 2
0A
1A♯B♭
2BC♭
3CB♯
4C♯D♭
5D
6D♯E♭
7EF♭
8FE♯
9F♯G♭
10G
11G♯A♭

A triad consists of a root note on the bottom followed by two thirds stacked on top of it. Thirds describe the distance between the preceding and following note. A third can be either of two types:

NameDistanceExample
Minor third3A C (note 0 to note 3)
Major third4C E (note 3 to note 7)

Being that there are 2 thirds in a triad and each third can be of 2 different types, there are 4 total “types” of triads. They are:

Triad NameThirds (Bottom to Top)Example
Diminished TriadMinor, MinorB D F
Minor TriadMinor, MajorE G B
Major TriadMajor, MinorC E G
Augmented TriadMajor, MajorD F♯ A♯

Input:

  • Triads of notes will always be written out so that the letters in the name used ascend by 2 between each third (wrapping back to A after G). Therefore, a triad consisting of notes 3, 6, and 9 may be written as B♯ D♯ F♯ or C E♭ G♭, but not, for example, as C D♯ F♯.
  • The notes may appear in any order, e.g., C E G and E C G both may appear.

Output:

  • Chords are named by the root note followed by nothing for major, m for minor, ° U+00B0 for diminished, and + for augmented.
  • The spelling of the root note in the output must match the input, e.g. the expected output for C E♭ G♭ is , not B♯°.

Note: to find the root, look only at the letters. E G♯ C and E G♯ B♯ cannot be told apart by a method that only considers note distances. The root is the note whose letter comes 2 and 4 letters before the other two letters in the chord. The expected outputs are C+ and E+ respectively.

0 bytes, 0 chars
Restore solution
All
Compiled from AT&T syntax to x86-64 Linux. Use syscalls to write output.
ctrl + enter or

Delete Solution

Are you sure you want to delete your solution(s) for Musical Chords?

If you have seperate bytes and chars solutions then both will be deleted.

This is irreversible, please backup any code you care about.

Type I understand and press confirm to continue.