Find the keys

Rick Deckard falls asleep while Rachael plays the piano and lets down
her hair.

DECKARD: I dreamt music.

RACHAEL: I didn’t know if I could play. I remember lessons. I don’t know
if it’s me or Tyrell’s niece.

Rachael softly plays thirteen notes on the piano: (2.8,0)[image]

DECKARD: You play beautifully.

RACHAEL: I remember well there are twelve different notes: C, C#, D, D#,
E, F, F#, G, G#, A, A# and B; and then comes C again. However, if I play
in the key of C, I can’t use the second, the fourth, the seventh, the
ninth nor the eleventh notes, that is, C#, D#, F#, G# nor A#.

Rachael plays a scale of C: (1.8,0)[image]

RACHAEL: However, if I play in the key of, say E, I can’t use the
second, the fourth, the seventh, the ninth nor the eleventh notes
either, but now starting from E, that is, F, G, A#, C nor D.

Rachael plays a scale of E: (2,0)[image]

DECKARD: If I play a tune, can you tell me the key it is in?

RACHAEL: Of course!

Deckard plays some notes: (2,0)[image]

ifnextchar ( ifnextchar (offsettrue(0pt,0pt) offsetfalse ifnextchar
[(0pt,0pt)(0pt,0pt) ifnextchar
[(0pt,0pt)(0pt,0pt)[l](0pt,0pt)(0pt,0pt)[l][] [r][image]

Rachael covers her face with her hand…

* * *

Despite Deckard’s clumsy attempts at musical art, can you write a
program such that, given a sequence of notes, tells the possible keys
the tune is written in?

Input

Input consists of several cases. Every case begins with a number n
followed by n notes. Note names are uppercase letters from A to G,
optionally suffixed by #. There are no E# nor B# notes.

Output

For every case, print a lexicographically sorted list of the possible
keys the tune is written in. If a tune cannot belong to any key, print
“None”.

Problem information

Author: Èdgar Gonzàlez

Generation: 2026-01-25T10:38:35.901Z

© Jutge.org, 2006–2026.
https://jutge.org
