Created
September 11, 2013 19:16
-
-
Save jorgebastida/6528404 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://icpc.kattis.com/problems/chopin | |
import sys | |
EXCEPTIONS = ('Ab minor', 'D# major', 'A# major', 'D# minor', 'A# minor', 'Gb major', 'C# major', 'Gb minor', 'Db minor', 'G# major') | |
inverse = lambda x: {'b': '#', '#': 'b'}[x] | |
alternate = lambda scale: '{0}{1}'.format(chr((((ord(scale[0]) + {'b': -1, '#': 1}[scale[1]]) - 65) % 7) + 65), inverse(scale[1])) | |
def translate(note): | |
scale, tone = note.split() | |
if len(scale) == 1: | |
return 'UNIQUE' | |
out = '{0} {1}'.format(alternate(scale), tone) | |
if out in EXCEPTIONS: | |
return note | |
return out | |
if __name__ == '__main__': | |
with open(sys.argv[1]) as f: | |
for number, line in enumerate(f): | |
print 'Case {0}: {1}'.format(number + 1, translate(line)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ab minor | |
D# major | |
G minor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Case 1: G# minor | |
Case 2: Eb major | |
Case 3: UNIQUE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment