cj gs

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

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 1 Name 2
0 A
1 A♯ B♭
2 B C♭
3 C B♯
4 C♯ D♭
5 D
6 D♯ E♭
7 E F♭
8 F E♯
9 F♯ G♭
10 G
11 G♯ 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:

Name Distance Example
Minor third 3 A C (note 0 to note 3)
Major third 4 C 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 Name Thirds (Bottom to Top) Example
Diminished Triad Minor, Minor B D F
Minor Triad Minor, Major E G B
Major Triad Major, Minor C E G
Augmented Triad Major, Major D 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.

External links: Wikipedia

0 bytes, 0 chars
Restore solution
All
Compiled from AT&T syntax to x86-64 Linux. Use syscalls to write output.
05AB1E is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
ALGOL 68 is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
APL is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Arturo is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Befunge is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
BQN is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
CJam is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
CoffeeScript is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Egel is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Fennel is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Gleam is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Groovy is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Harbour is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Hare is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Haxe is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Hush is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Hy is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Odin is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Racket is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Rebol is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Rexx is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Scala is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Squirrel is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
Uiua is an experimental language, no solutions will be saved. Please leave feedback on the GitHub issue.
ctrl + enter or

Delete Solution

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

If you have separate 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.