38
12
Input
The symbol of any triadic chord (see http://en.wikipedia.org/wiki/Chord_(music)#Triads).
Output
The notes constituting the given chord.
Examples
Input: AM
Output: A C# E
Input: C#m
Output: C# E G#
Input: Db+
Output: C# F A
Input: C0
Output: C D# F#
Bonuses
-50 if you can also deal with seventh chords
-150 for actually playing the sound of the chord
-150 for using printable characters to show how to play the chord on a piano; example for AM
:
┌─┬─┬┬─┬─┬─┬─┬┬─┲┱─┬─┬─┲━┱┬─┲━┱─┬─┬┬─┬┬─┬─┐
│ │ ││ │ │ │ ││ ┃┃ │ │ ┃ ┃│ ┃ ┃ │ ││ ││ │ │
│ │ ││ │ │ │ ││ ┃┃ │ │ ┃ ┃│ ┃ ┃ │ ││ ││ │ │
│ │ ││ │ │ │ ││ ┃┃ │ │ ┃ ┃│ ┃ ┃ │ ││ ││ │ │
│ └┬┘└┬┘ │ └┬┘└┲┛┗┱┘ │ ┗┯┛└┲┛ ┃ └┬┘└┬┘└┬┘ │
│ │ │ │ │ ┃ ┃ │ │ ┃ ┃ │ │ │ │
└──┴──┴──┴──┴──┺━━┹──┴──┴──┺━━┹──┴──┴──┴──┘
-100 for using printable characters to show how to play the chord on a guitar; example for AM
:
x o o o o o
┌───┬───┬───┬───┬───┐
│ │ │ │ │ │
├───┼───┼───┼───┼───┤
│ │ │ │ │ │
├───┼───┼───┼───┼───┤
│ │ █ █ █ │
├───┼───┼───┼───┼───┤
│ │ │ │ │ │
(see https://en.wikipedia.org/wiki/Box-drawing_character)
Rules
The result must be a command-line program or script.
The input and output can be in any form, as long as it follows a music notation standard.
A guitar or piano representation is considered valid if and only if it contains the three (triadic) or four (seventh) required notes and nothing else. The same note can be present several times in the chord.
External libraries are not allowed, except for sound generation (in which case the
#include
,import
... directives are not added to the character count).This is code golf, the shortest code wins!
A little bit of music theory...
In modern Western tonal music, every octave is made of twelve successive notes, often noted:
A
A#
B
C
C#
D
D#
E
F
F#
G
G#
Or:
La
La#
Si
Do
Do#
Re
Re#
Mi
Fa
Fa#
Sol
Sol#
In this system, we consider that two successive notes (e.g. A
and A#
, or E
and F
) are separated by one semitone. Also, the notes are kind of "looping": what immediately follows G#
is A
.
A chord is constituted by a few (2, 3, 4, sometimes more) notes that "sound good together". For instance, triadic chords contain three different notes, and seventh chords contain four different notes.
Let's define the four triadic chords as:
Major triad: contains the root of the chord (in this question, the note given as input), the major third for the root (4 semitones higher than the root), and the perfect fifth for the root (7 semitones higher than the root); this can be symbolized 0-4-7
Minor triad, symbolized 0-3-7
Augmented triad, symbolized 0-4-8
Diminished triad, symbolized 0-3-6
So for example, if you want to make a C major triad, noted C
, CM
, Cmaj
, you will need three noted:
- 0: the root, in this case a
C
- 4: the minor third, 4 semitones higher than the root; that's an
E
- 7: the perfect fifth, 7 semitones higher than the root: a
G
This is what the 0-4-7
, 0-3-7
, 0-4-8
and 0-3-6
notations used above mean! For the seventh chords, use the following pattern:
That's it for today! Now, amaze me with amazing code... If you have any question, add some comments below.
Just an FYI, the guitar chord you have as AM is more like Bb... – Beta Decay – 2017-05-28T07:43:18.477
Kind-of the inverse of this older question.
– Peter Taylor – 2014-03-24T15:50:31.567Yes, I found it too when checking for duplicates... but even if both questions are about chords, the way to the solution is quite different! – Mathieu Rodic – 2014-03-24T15:54:35.487
1It might be worth adding an explanation including the formulas for the chords in integer notation for non musicians. Integer notation refers to everything in semitones. Major chord (Example AM): 0,4,7. Minor chord (example C#m): 0,3,7. C diminished (Example Co, or as you call it C0) 0,3,6 (note that the correct representation is C Eb Gb, but for this challenge I guess we can assume both this and C D# F# are acceptable.) The formula for an augmented chord (Example Db+) is 0,4,8 and your example is wrong as it doesn't even contain a Db. As written it is a B+ which is equivalent to a D#+ or G+ – Level River St – 2014-03-24T17:12:26.417
Also, when you consider adding a seventh to all of these triads, there are a bewildering number of possibilities. Can we assume the challenge is limited to the dominant seventh? (formula 0,4,7,10) Example G B D F. – Level River St – 2014-03-24T17:14:43.503
Finally, does the chord inversion on the piano have to be one with the root as the lowest note? I assume any valid inversion is acceptable on the guitar, as the "standard" inversion on the piano is often impossible on the guitar. Note that one of the most inversions for C7 on the guitar does not even contain a G: http://music.stackexchange.com/questions/12205/why-does-the-c7-chord-on-guitar-omit-the-g-note-5th-in-open-position.
– Level River St – 2014-03-24T17:20:15.0633Also, shortest code will result from use of the same chord shape for all guitar chords of the same type, barred. So Ab will be an A shape barred at the 11th fret. Is it Ok to put a number or do we have to draw 11 frets? All in all, it's a lot of things to think about. You may want to simplify the bonuses. – Level River St – 2014-03-24T17:29:11.693
By the way, I do like the question :-) – Level River St – 2014-03-24T17:38:36.537
@steveverrill: a lot of constructive comments... I am editing the question :) – Mathieu Rodic – 2014-03-24T20:22:18.277
@steveverrill: phew! I added some precisions and a bit of music theory. The result is terribly long, and I'm not sure it will be of much help for music newbies... – Mathieu Rodic – 2014-03-24T21:34:03.633
1Hmm.. your augmented chord is still wrong. C# is enharmonic to Db, but
Db+
isDb F A
there's no D# or G in there. That's perhaps a little more theory than necessary, the formulas were the important part. If you really want to include all eight of the seventh chords listed in wikipedia you should specify the input. I assume the ascii-art output of piano and guitar is flexible. – Level River St – 2014-03-24T22:04:39.450Oops indeed. Edited. – Mathieu Rodic – 2014-03-24T22:09:49.267
"The input and output can be in any form, as long as it follows a music notation standard." How much are we allowed to restrict it? Can we say only
C#
is accepted and neglect the equivalentDb
, or vice versa? Can we use/requireh
in place of#
? Do we have to support both ofCM Cmaj
or just one? – algorithmshark – 2014-03-24T22:50:02.377@algorithmshark: it means you can follow the standard(s) of your choice, as long as you remain consistent. – Mathieu Rodic – 2014-03-24T22:53:21.037
What do you think about including
F#
in the tonal scale? – tomsmeding – 2014-03-25T07:03:34.8503I feel like I've learned more about music theory here than I've learned from lessons. – Kevin Evans – 2014-03-28T22:37:24.020
4The coolest problem on this site ! – Ray – 2014-03-31T17:16:53.287
You could also add a bonus for accepting a key, major/minor/augmented/diminished, and a figured bass to determine the chord. – Justin – 2014-04-03T20:22:11.130